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.
Quick start
Section titled “Quick start”Option A: JWT (interactive sessions)
Section titled “Option A: JWT (interactive sessions)”# 1. Registercurl -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 responsecurl https://qubithub.co/api/auth/me \ -H "Authorization: Bearer <access_token>"Option B: API key (programmatic access)
Section titled “Option B: API key (programmatic access)”# 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.Option C: CLI authentication
Section titled “Option C: CLI authentication”qubithub login # Prompts for your email or username, and passwordqubithub login --token eyJhbG... # Non-interactive JWT authVerify you’re authenticated:
qubithub whoamiJWT authentication
Section titled “JWT authentication”Register
Section titled “Register”Create a new account. Returns tokens immediately (auto-login).
POST /auth/registerRequest body:
| Field | Type | Required | Constraints |
|---|---|---|---|
email | string | Yes | Valid email address |
username | string | Yes | 4-39 chars, lowercase alphanumeric and hyphens, must start and end with alphanumeric |
password | string | Yes | Minimum 8 characters |
name | string | Yes | Display name |
terms_accepted | boolean | Yes | Must be true: you agree to the Terms of Service and Privacy Policy |
terms_version | string | Yes | The current Terms version; it must match the server’s (today 1.0.0-draft) |
privacy_version | string | Yes | The current Privacy Policy version; it must match the server’s (today 1.0.0-draft) |
turnstile_token | string | No | The bot-check token the web sign-up form sends |
Example request:
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", "username": "alice-q", "name": "Alice Quantum", "avatar": null, "organizations": null }}Errors:
| Status | Cause |
|---|---|
400 | Email already registered |
403 | The bot check failed (a missing or invalid turnstile_token where the server checks it) |
409 | The username is taken (by a user or an organization) |
422 | A 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/loginRequest body:
| Field | Type | Required | Description |
|---|---|---|---|
identifier | string | Yes* | Your email address (any capitalisation) or your username |
email | string | Yes* | The same as identifier; kept for clients written before it existed |
password | string | Yes | Your password |
mfa_code | string | No | MFA code (coming soon, not yet available) |
* Send exactly one of identifier and email. Both, or neither, returns 422.
Example request:
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", "username": "alice-q", "name": "Alice Quantum", "avatar": null, "organizations": null }}Errors:
| Status | Cause |
|---|---|
401 | Invalid email, username or password |
403 | Account is inactive |
429 | Too many attempts (see Rate limits) |
Using access tokens
Section titled “Using access tokens”Include the access token in the Authorization header of every authenticated request:
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.
Refresh tokens
Section titled “Refresh tokens”Access tokens are short-lived (15 minutes). Refresh tokens last 30 days and are used to obtain new access tokens.
POST /auth/refreshRefresh tokens are delivered in two ways:
- httpOnly cookie (automatic for browsers): most secure, no JavaScript access
- Response body: for non-browser clients (CLI, SDK, scripts)
Browser clients (cookie is sent automatically):
curl -X POST https://qubithub.co/api/auth/refresh \ --cookie "refresh_token=eyJhbGciOiJIUzI1NiIs..."Non-browser clients (pass in request body):
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:
| Status | Cause |
|---|---|
400 | No refresh token provided |
401 | Token expired, revoked, or invalid |
Get current user
Section titled “Get current user”GET /auth/meReturns the authenticated user’s profile, including organization memberships.
curl https://qubithub.co/api/auth/me \ -H "Authorization: Bearer <access_token>"Example response (200 OK):
{ "id": "550e8400-e29b-41d4-a716-446655440000", "username": "alice-q", "name": "Alice Quantum", "avatar": null, "organizations": [ { "id": "660e8400-e29b-41d4-a716-446655440000", "name": "Alice's Organization", "role": "owner" } ]}List organizations
Section titled “List organizations”GET /auth/orgsReturns all organizations the current user belongs to, with their role in each.
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" }]Logout
Section titled “Logout”POST /auth/logoutRevokes the refresh token and clears the cookie. Returns 204 No Content.
curl -X POST https://qubithub.co/api/auth/logout \ -H "Authorization: Bearer <access_token>"Password reset
Section titled “Password reset”Step 1: Request reset email
POST /auth/forgot-passwordcurl -X POST https://qubithub.co/api/auth/forgot-password \ -H "Content-Type: application/json" \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-passwordcurl -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:
| Status | Cause |
|---|---|
400 | Token expired (>1 hour) or invalid; already used, or the account’s password or email changed since it was sent; password too short |
403 | Account is inactive |
404 | User not found |
Change email
Section titled “Change email”Changing the address takes two steps. Nothing changes until the second one.
Step 1: Request the change (signed in)
POST /auth/change-emailcurl -X POST https://qubithub.co/api/auth/change-email \ -H "Authorization: Bearer <access_token>" \ -H "Content-Type: application/json" \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-changecurl -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.
| Status | detail.code | Cause |
|---|---|---|
400 | current_password_incorrect | Wrong password (step 1) |
400 | email_unchanged | That is already the account’s address |
400 | link_expired, link_invalid, link_spent | The link is past 24 hours, not a valid link, or already used (or the email or password changed since it was sent) |
400 | link_for_another_account | You are signed in to a different account |
409 | email_in_use | Another account has that address |
409 | git_server_refused, git_account_mismatch | The git server would not take the new address; nothing changed |
429 | More than 5 requests in an hour (step 1) | |
503 | git_server_unavailable | The git server could not be reached; nothing changed, and the link still works |
API key authentication
Section titled “API key authentication”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.
Create an API key
Section titled “Create an API key”Requires JWT authentication. The plaintext key is returned only once. Save it immediately.
POST /api-keysRequest body:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Descriptive name (e.g., “CI/CD Pipeline”) |
scopes | string[] | Yes | Permission scopes (see Scopes below) |
expires_in_days | integer | No | Expiration in days (1-365). null = no expiration |
rate_limit_per_minute | integer | No | Recorded on the key; not enforced yet |
Example request:
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"}Using API keys
Section titled “Using API keys”Once API key authentication is enabled on routes, include the key in the X-API-Key header:
curl https://qubithub.co/api/circuits \ -H "X-API-Key: qh_a1b2c3d4e5f6g7h8i9j0..."Scopes
Section titled “Scopes”Scopes control what an API key is allowed to do. Assign only the scopes your use case needs.
| Scope | Description |
|---|---|
circuit:read | Read circuit metadata, files, and versions |
circuit:write | Create, update, and delete circuits |
dataset:read | Read dataset metadata and contents |
dataset:write | Create, update, and delete datasets |
runs:submit | Submit circuit execution jobs |
org:read | Read organization details |
org:write | Manage organization settings and members |
repo:read | Read repository contents |
repo:write | Push to repositories |
Example scope combinations:
| Use case | Scopes |
|---|---|
| Read-only dashboard | circuit:read, dataset:read |
| CI/CD pipeline | circuit:read, circuit:write, runs:submit |
| Organization tooling | org:read, circuit:read, repo:read |
List API keys
Section titled “List API keys”GET /api-keysReturns all your active API keys (without plaintext values).
curl https://qubithub.co/api/api-keys \ -H "Authorization: Bearer <access_token>"To include revoked keys, add ?include_inactive=true.
Get a single API key
Section titled “Get a single API key”GET /api-keys/{key_id}Returns details of a specific API key. You must be the key’s creator.
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:
| Status | Cause |
|---|---|
403 | Not the key’s creator |
404 | Key not found |
Revoke an API key
Section titled “Revoke an API key”DELETE /api-keys/{key_id}Immediately deactivates the key. Returns 204 No Content.
curl -X DELETE https://qubithub.co/api/api-keys/770e8400-e29b-41d4-a716-446655440000 \ -H "Authorization: Bearer <access_token>"Rate limits
Section titled “Rate limits”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.
Python examples
Section titled “Python examples”JWT authentication
Section titled “JWT authentication”import requests
BASE_URL = "https://qubithub.co/api"
# Loginresponse = requests.post(f"{BASE_URL}/auth/login", json={ "password": "Qu4ntum!Leap#42",})tokens = response.json()access_token = tokens["access_token"]refresh_token = tokens["refresh_token"]
# Make authenticated requestsheaders = {"Authorization": f"Bearer {access_token}"}me = requests.get(f"{BASE_URL}/auth/me", headers=headers)print(me.json())
# Refresh when the access token expiresresponse = requests.post(f"{BASE_URL}/auth/refresh", json={ "refresh_token": refresh_token,})access_token = response.json()["access_token"]API key authentication (coming soon)
Section titled “API key authentication (coming soon)”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())Token refresh pattern
Section titled “Token refresh pattern”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 respSecurity best practices
Section titled “Security best practices”-
Use API keys for git automation,
qubithub loginfor 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. -
Set expiration on API keys. Use
expires_in_daysto limit the blast radius if a key is leaked. 90 days is a reasonable default for CI/CD. -
Use the minimum scopes needed. A monitoring script only needs
circuit:read, notcircuit:write. -
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 osapi_key = os.environ["QUBITHUB_API_KEY"] -
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. -
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.
-
Rotate keys periodically. Create a new key, update your systems, then revoke the old one.
Error reference
Section titled “Error reference”Common authentication errors across all endpoints:
| Status | Header | Meaning |
|---|---|---|
400 | — | Bad request (missing fields, invalid format, password too short) |
401 | WWW-Authenticate: Bearer | Missing or invalid access token / API key |
403 | — | Account inactive, or not authorized for this resource |
404 | — | Resource not found |
Token lifecycle errors:
| Scenario | Status | Detail |
|---|---|---|
| Access token expired | 401 | Refresh using POST /auth/refresh |
| Refresh token expired (>30 days) | 401 | Log in again with POST /auth/login |
| API key revoked | 401 | Create a new key via POST /api-keys |
| API key expired | 401 | Create a new key with a new expiration |
| Insufficient scopes | 403 | Create a new key with the required scopes |
Next steps
Section titled “Next steps”- CLI Quickstart: get up and running with the CLI
- Web UI Guide: browse and run circuits in the browser
- qubithub.toml Reference: circuit manifest specification
- API Reference: full endpoint documentation