QRNG API Quickstart Guide

Introduction

We are providing API access to our uQRNG service free of charge to users during our initial launch. Users can access up to 1 billion bits from the uQRNG service per month with a maximum requests size of 1 million QRNs.Need more QRNs, please contact us at support@quantumcomputinginc.com.

The first step to start using QCI’s QRNG-API is to contact QCI’s sales team at support@quantumcomputinginc.com. You will receive an email response with an API access token and instructions on how to get started.Using your access token, you’ll authenticate with the QRNG service (standard OAuth 2.0 authentication) and use the refresh token obtained from the authentication process in subsequent requests to the QRNG service. Examples of authenticating and making QRNG requests are shown below using the curl, Python, and R programming languages:

Access Token

cURL

ACCESS_TOKEN=`curl -X "POST" \
-H "Content-Type: application/json" \
-d "{ \"access_token\": \"user-API-Token\" }" \
https://api.qci-next.com/authorize | jq -r ".access_token"`

Python

import requests
json_data = {
"access_token": f"{api_token}",
}
headers = {
"accept": "application/json",
"Content-Type": "application/json",
}
response=requests.post(
f"{qrng_url}/authorize",
headers=headers,
json=json_data)
response_json = response.json()
print(response_json)
access_token = response.json().get("access_token")

R

require(httr)
api_token = "user_api_token"
qrng_url = "https://api.qci-next.com"
headers = c(`Content-Type` = "application/json")
data = list(access_token = api_token)
response <- httr::POST(
url = paste(qrng_url, "authorize", sep="/"),
httr::add_headers(.headers=headers),
encode = "json",
body = data)
auth_resp = content(response,as="parsed")

Output

{"access_token":"user-Bearer-Token","expires_in":1680287957,"scope":"access_token","token_type":"bearer"}

Making calls

Once the user has obtained the Bearer token calls can be made to the QRNG-API as follows:

cURL

QRNS=`curl -X 'POST' \
-H "accept: application/json" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{ "distribution": "uniform_discrete", "output_type": "decimal", "n_samples": 5, "n_bits": 16 }' \
https://api.qci-next.com/qrng/random_numbers`
echo ${QRNS}

Python

headers = {
"accept": "application/json",
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}
json_data = {
"distribution": "uniform_discrete",
"output_type": "decimal",
"n_samples": 5,
"n_bits": 16
}
response = requests.post(
f"{qrng_url}/qrng/random_numbers",
headers=headers,
json=json_data)
print(response.json())

R

require(jsonlite)
# BEARER_TOKEN is taken from access_token in authorize response
BEARER_TOKEN = auth_resp$access_token
headers = c(
`Authorization` = paste("Bearer", BEARER_TOKEN, sep = " "),
`Content-Type` = "application/json"
)
data = list(distribution ="uniform_discrete",
n_samples=5,
n_bits=16,
output_type="decimal")
response <- httr::POST(
url =paste(qrng_url, "qrng", "random_numbers", sep="/"),
httr::add_headers(.headers=headers),
body = data,
encode="json")
numbers_resp = fromJSON(content(response, as="text", encoding = "ISO-8859-1"))

Output

[5845, 7686, 2788, 7021, 1913]

Usage statistics

To check QRNG service usage statistics (reported as the number of bits of QRN data consumed for a given time period:

cURL

USAGE=`curl -X 'POST' \
-H "Accept: application/json" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{ "start_date": "2023-04-14", "end_date": "2023-04-15" }' \
https://api.qci-next.com/qrng/usage`
echo ${USAGE}

Python

headers = {
"Accept": "application/json",
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}
json_data = {
"start_date": "2023-04-15",
"end_date": "2023-04-16"
}
response = requests.post(
f"{qrng_url}/qrng/usage",
headers=headers,
json=json_data)
print(response.json())

R

# BEARER_TOKEN is taken from access_token in authorize response
BEARER_TOKEN = auth_resp$access_token
headers = c(
`Authorization` = paste("Bearer", BEARER_TOKEN, sep = " "),
`Content-Type` = "application/json"
)
data = list(start_date ="2023-04-14",
end_date= "2023-04-15")
response <- httr::POST(
url = paste(qrng_url, "qrng", "usage", sep="/"),
httr::add_headers(.headers=headers),
body = data,
encode = "json")
usage_resp = content(response,as="parsed")

Output

{'n_bits': 48077040}

Resources

For further information on features and usage of API see full API reference guide here.

Open API specification is available at https://api.qci-next.com/qrng/docs