Skip to content

Authentication

QubitHub supports two authentication methods:

  • JWT tokens: for browser sessions, interactive use, and all API endpoints
  • API keys: for future programmatic access (scripts, CI/CD, SDK)

All API endpoints currently require JWT authentication. API key infrastructure is built and keys can be created and managed, but route-level API key authentication is not yet enabled. This guide documents both methods so you can create keys now and use them as endpoint support is added.


Terminal window
# 1. Register
curl -X POST https://qubithub.co/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"username": "your-username",
"password": "s3cure-Passw0rd!",
"name": "Your Name",
"terms_accepted": true,
"terms_version": "1.0.0-draft",
"privacy_version": "1.0.0-draft"
}'
# 2. Use the access_token from the response
curl https://qubithub.co/api/auth/me \
-H "Authorization: Bearer <access_token>"
Terminal window
# 1. Create an API key (requires JWT auth first)
curl -X POST https://qubithub.co/api/api-keys \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "my-script",
"scopes": ["circuit:read", "circuit:write"]
}'
# 2. Save the key from the response — you'll use it once API key auth is enabled
# API key route support is coming soon. For now, use JWT for all requests.
Terminal window
qubithub login # Prompts for your email or username, and password
qubithub login --token eyJhbG... # Non-interactive JWT auth

Verify you’re authenticated:

Terminal window
qubithub whoami

Create a new account. Returns tokens immediately (auto-login).

POST /auth/register

Request body:

FieldTypeRequiredConstraints
emailstringYesValid email address
usernamestringYes4-39 chars, lowercase alphanumeric and hyphens, must start and end with alphanumeric
passwordstringYesMinimum 8 characters
namestringYesDisplay name
terms_acceptedbooleanYesMust be true: you agree to the Terms of Service and Privacy Policy
terms_versionstringYesThe current Terms version; it must match the server’s (today 1.0.0-draft)
privacy_versionstringYesThe current Privacy Policy version; it must match the server’s (today 1.0.0-draft)
turnstile_tokenstringNoThe bot-check token the web sign-up form sends

Example request:

Terminal window
curl -X POST https://qubithub.co/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"username": "alice-q",
"password": "Qu4ntum!Leap#42",
"name": "Alice Quantum",
"terms_accepted": true,
"terms_version": "1.0.0-draft",
"privacy_version": "1.0.0-draft"
}'

Example response (201 Created):

{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer",
"expires_in": 900,
"user": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"email": "[email protected]",
"username": "alice-q",
"name": "Alice Quantum",
"avatar": null,
"organizations": null
}
}

Errors:

StatusCause
400Email already registered
403The bot check failed (a missing or invalid turnstile_token where the server checks it)
409The username is taken (by a user or an organization)
422A field fails validation (for example a short password, an invalid or reserved username, or terms not accepted or out of date)

Sign in with your email address or your username, and your password.

POST /auth/login

Request body:

FieldTypeRequiredDescription
identifierstringYes*Your email address (any capitalisation) or your username
emailstringYes*The same as identifier; kept for clients written before it existed
passwordstringYesYour password
mfa_codestringNoMFA code (coming soon, not yet available)

* Send exactly one of identifier and email. Both, or neither, returns 422.

Example request:

Terminal window
curl -X POST https://qubithub.co/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"identifier": "alice-q",
"password": "Qu4ntum!Leap#42"
}'

Example response (200 OK):

{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer",
"expires_in": 900,
"user": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"email": "[email protected]",
"username": "alice-q",
"name": "Alice Quantum",
"avatar": null,
"organizations": null
}
}

Errors:

StatusCause
401Invalid email, username or password
403Account is inactive
429Too many attempts (see Rate limits)

Include the access token in the Authorization header of every authenticated request:

Terminal window
curl https://qubithub.co/api/auth/me \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Access tokens expire after 15 minutes. Use the refresh endpoint to get a new one without re-entering credentials.

Access tokens are short-lived (15 minutes). Refresh tokens last 30 days and are used to obtain new access tokens.

POST /auth/refresh

Refresh tokens are delivered in two ways:

  1. httpOnly cookie (automatic for browsers): most secure, no JavaScript access
  2. Response body: for non-browser clients (CLI, SDK, scripts)

Browser clients (cookie is sent automatically):

Terminal window
curl -X POST https://qubithub.co/api/auth/refresh \
--cookie "refresh_token=eyJhbGciOiJIUzI1NiIs..."

Non-browser clients (pass in request body):

Terminal window
curl -X POST https://qubithub.co/api/auth/refresh \
-H "Content-Type: application/json" \
-d '{"refresh_token": "eyJhbGciOiJIUzI1NiIs..."}'

Example response (200 OK):

{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer"
}

Errors:

StatusCause
400No refresh token provided
401Token expired, revoked, or invalid
GET /auth/me

Returns the authenticated user’s profile, including organization memberships.

Terminal window
curl https://qubithub.co/api/auth/me \
-H "Authorization: Bearer <access_token>"

Example response (200 OK):

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"email": "[email protected]",
"username": "alice-q",
"name": "Alice Quantum",
"avatar": null,
"organizations": [
{
"id": "660e8400-e29b-41d4-a716-446655440000",
"name": "Alice's Organization",
"role": "owner"
}
]
}
GET /auth/orgs

Returns all organizations the current user belongs to, with their role in each.

Terminal window
curl https://qubithub.co/api/auth/orgs \
-H "Authorization: Bearer <access_token>"

Example response (200 OK):

[
{
"id": "660e8400-e29b-41d4-a716-446655440000",
"name": "Alice's Organization",
"role": "owner"
},
{
"id": "770e8400-e29b-41d4-a716-446655440000",
"name": "Quantum Research Lab",
"role": "member"
}
]
POST /auth/logout

Revokes the refresh token and clears the cookie. Returns 204 No Content.

Terminal window
curl -X POST https://qubithub.co/api/auth/logout \
-H "Authorization: Bearer <access_token>"

Step 1: Request reset email

POST /auth/forgot-password
Terminal window
curl -X POST https://qubithub.co/api/auth/forgot-password \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]"}'

Always returns 204 No Content (prevents email enumeration). If the email exists, a reset link is sent with a 1-hour expiry.

Step 2: Reset password with token

POST /auth/reset-password
Terminal window
curl -X POST https://qubithub.co/api/auth/reset-password \
-H "Content-Type: application/json" \
-d '{
"token": "eyJhbGciOiJIUzI1NiIs...",
"password": "N3w$ecure!Pass99"
}'

Returns 204 No Content on success. All existing sessions are invalidated, so you must log in again on all devices.

Errors:

StatusCause
400Token expired (>1 hour) or invalid; already used, or the account’s password or email changed since it was sent; password too short
403Account is inactive
404User not found

Changing the address takes two steps. Nothing changes until the second one.

Step 1: Request the change (signed in)

POST /auth/change-email
Terminal window
curl -X POST https://qubithub.co/api/auth/change-email \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"new_email": "[email protected]", "password": "Qu4ntum!Leap#42"}'

Returns 204 No Content. A one-time link goes to the new address and expires after 24 hours. The current address gets a notice with no link in it; if you didn’t ask for the change, changing your password cancels it.

Step 2: Open the link, while signed in to the same account, and confirm. The web page sends:

POST /auth/confirm-email-change
Terminal window
curl -X POST https://qubithub.co/api/auth/confirm-email-change \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"token": "eyJhbGciOiJIUzI1NiIs..."}'

Returns a new token pair, like a login. The address changes and counts as verified, and every other session is signed out. Reset and verification links sent to the old address stop working.

Errors: refusals carry detail.code.

Statusdetail.codeCause
400current_password_incorrectWrong password (step 1)
400email_unchangedThat is already the account’s address
400link_expired, link_invalid, link_spentThe link is past 24 hours, not a valid link, or already used (or the email or password changed since it was sent)
400link_for_another_accountYou are signed in to a different account
409email_in_useAnother account has that address
409git_server_refused, git_account_mismatchThe git server would not take the new address; nothing changed
429More than 5 requests in an hour (step 1)
503git_server_unavailableThe git server could not be reached; nothing changed, and the link still works

API keys are for programmatic access: CI/CD pipelines, scripts, the QubitHub SDK, or any automated workflow. They do not expire by default and support fine-grained scopes.

Requires JWT authentication. The plaintext key is returned only once. Save it immediately.

POST /api-keys

Request body:

FieldTypeRequiredDescription
namestringYesDescriptive name (e.g., “CI/CD Pipeline”)
scopesstring[]YesPermission scopes (see Scopes below)
expires_in_daysintegerNoExpiration in days (1-365). null = no expiration
rate_limit_per_minuteintegerNoRecorded on the key; not enforced yet

Example request:

Terminal window
curl -X POST https://qubithub.co/api/api-keys \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "CI/CD Pipeline",
"scopes": ["circuit:read", "runs:submit"],
"expires_in_days": 90,
"rate_limit_per_minute": 100
}'

Example response (201 Created):

{
"id": "770e8400-e29b-41d4-a716-446655440000",
"name": "CI/CD Pipeline",
"key": "qh_a1b2c3d4e5f6g7h8i9j0...",
"key_prefix": "qh_a1b2c",
"scopes": ["circuit:read", "runs:submit"],
"rate_limit_per_minute": 100,
"expires_at": "2026-06-25T12:00:00",
"created_at": "2026-03-27T12:00:00"
}

Once API key authentication is enabled on routes, include the key in the X-API-Key header:

Terminal window
curl https://qubithub.co/api/circuits \
-H "X-API-Key: qh_a1b2c3d4e5f6g7h8i9j0..."

Scopes control what an API key is allowed to do. Assign only the scopes your use case needs.

ScopeDescription
circuit:readRead circuit metadata, files, and versions
circuit:writeCreate, update, and delete circuits
dataset:readRead dataset metadata and contents
dataset:writeCreate, update, and delete datasets
runs:submitSubmit circuit execution jobs
org:readRead organization details
org:writeManage organization settings and members
repo:readRead repository contents
repo:writePush to repositories

Example scope combinations:

Use caseScopes
Read-only dashboardcircuit:read, dataset:read
CI/CD pipelinecircuit:read, circuit:write, runs:submit
Organization toolingorg:read, circuit:read, repo:read
GET /api-keys

Returns all your active API keys (without plaintext values).

Terminal window
curl https://qubithub.co/api/api-keys \
-H "Authorization: Bearer <access_token>"

To include revoked keys, add ?include_inactive=true.

GET /api-keys/{key_id}

Returns details of a specific API key. You must be the key’s creator.

Terminal window
curl https://qubithub.co/api/api-keys/770e8400-e29b-41d4-a716-446655440000 \
-H "Authorization: Bearer <access_token>"

Example response (200 OK):

{
"id": "770e8400-e29b-41d4-a716-446655440000",
"name": "CI/CD Pipeline",
"key_prefix": "qh_a1b2c",
"scopes": ["circuit:read", "runs:submit"],
"rate_limit_per_minute": 100,
"is_active": true,
"last_used_at": "2026-03-27T14:30:00",
"expires_at": "2026-06-25T12:00:00",
"created_at": "2026-03-27T12:00:00"
}

Errors:

StatusCause
403Not the key’s creator
404Key not found
DELETE /api-keys/{key_id}

Immediately deactivates the key. Returns 204 No Content.

Terminal window
curl -X DELETE https://qubithub.co/api/api-keys/770e8400-e29b-41d4-a716-446655440000 \
-H "Authorization: Bearer <access_token>"

API requests are rate limited per IP address. The limit is the same on every plan; there are no per-tier limits today. Past it, the API returns 429 with a Retry-After header.

POST /auth/login has two limits of its own, and both return 429 with a Retry-After header:

  • 10 attempts per minute per IP address, successful or not. Sending an API key or a bearer token does not change it.
  • 10 failed attempts per 15 minutes per email or username, counted separately for each. Past it, that email or username is refused for the rest of the 15 minutes, even with the right password. A password reset lifts it, and so does changing your email to that address.

import requests
BASE_URL = "https://qubithub.co/api"
# Login
response = requests.post(f"{BASE_URL}/auth/login", json={
"email": "[email protected]",
"password": "Qu4ntum!Leap#42",
})
tokens = response.json()
access_token = tokens["access_token"]
refresh_token = tokens["refresh_token"]
# Make authenticated requests
headers = {"Authorization": f"Bearer {access_token}"}
me = requests.get(f"{BASE_URL}/auth/me", headers=headers)
print(me.json())
# Refresh when the access token expires
response = requests.post(f"{BASE_URL}/auth/refresh", json={
"refresh_token": refresh_token,
})
access_token = response.json()["access_token"]

Once API key auth is enabled on routes, usage will look like:

import requests
BASE_URL = "https://qubithub.co/api"
API_KEY = "qh_a1b2c3d4e5f6g7h8i9j0..."
headers = {"X-API-Key": API_KEY}
# List circuits (requires API key route support — not yet enabled)
circuits = requests.get(f"{BASE_URL}/circuits", headers=headers)
print(circuits.json())

For long-running scripts, wrap your requests with automatic refresh:

import requests
class QubitHubClient:
def __init__(self, email: str, password: str, base_url: str = "https://qubithub.co/api"):
self.base_url = base_url
self._refresh_token = None
self._access_token = None
self._login(email, password)
def _login(self, email: str, password: str):
resp = requests.post(f"{self.base_url}/auth/login", json={
"email": email,
"password": password,
})
resp.raise_for_status()
data = resp.json()
self._access_token = data["access_token"]
self._refresh_token = data["refresh_token"]
def _refresh(self):
resp = requests.post(f"{self.base_url}/auth/refresh", json={
"refresh_token": self._refresh_token,
})
resp.raise_for_status()
self._access_token = resp.json()["access_token"]
def request(self, method: str, path: str, **kwargs):
headers = kwargs.pop("headers", {})
headers["Authorization"] = f"Bearer {self._access_token}"
resp = requests.request(method, f"{self.base_url}{path}", headers=headers, **kwargs)
if resp.status_code == 401:
self._refresh()
headers["Authorization"] = f"Bearer {self._access_token}"
resp = requests.request(method, f"{self.base_url}{path}", headers=headers, **kwargs)
return resp

  1. Use API keys for git automation, qubithub login for everything else. Today an API key authenticates git over HTTPS only; it can be revoked independently of your password. API access (the CLI, the SDK, curl) uses JWT until API key route support is enabled.

  2. Set expiration on API keys. Use expires_in_days to limit the blast radius if a key is leaked. 90 days is a reasonable default for CI/CD.

  3. Use the minimum scopes needed. A monitoring script only needs circuit:read, not circuit:write.

  4. Never commit keys to version control. Store API keys in environment variables or a secrets manager.

    Terminal window
    # .env (never commit this file)
    QUBITHUB_API_KEY=qh_a1b2c3d4e5f6g7h8i9j0...
    import os
    api_key = os.environ["QUBITHUB_API_KEY"]
  5. Revoke compromised keys immediately. If a key is exposed in logs, a commit, or a paste, revoke it via DELETE /api-keys/{id} and create a new one.

  6. Store refresh tokens securely. For browser clients, the httpOnly cookie handles this automatically. For CLI/SDK clients, store the refresh token in a secure location (keyring, encrypted config), not in plaintext files.

  7. Rotate keys periodically. Create a new key, update your systems, then revoke the old one.


Common authentication errors across all endpoints:

StatusHeaderMeaning
400—Bad request (missing fields, invalid format, password too short)
401WWW-Authenticate: BearerMissing or invalid access token / API key
403—Account inactive, or not authorized for this resource
404—Resource not found

Token lifecycle errors:

ScenarioStatusDetail
Access token expired401Refresh using POST /auth/refresh
Refresh token expired (>30 days)401Log in again with POST /auth/login
API key revoked401Create a new key via POST /api-keys
API key expired401Create a new key with a new expiration
Insufficient scopes403Create a new key with the required scopes