Developer API
A REST API over the same data the web app uses. Authenticate with a personal access token and you get GitHub-style rate-limit headers on every response.
Base URLs
| Use | URL |
|---|---|
| Web app + API | https://unit.plera.net |
| API (dedicated port) | https://unit.plera.net |
| OpenAPI schema | https://unit.plera.net/developer/openapi.json |
| GraphQL | https://unit.plera.net/graphql |
| Interactive docs | https://unit.plera.net/docs |
Both ports serve the same routes, database and rate limits. The API port exists so you can expose it separately behind a firewall or proxy.
Try it
Send a request from this page and read the response. Requests go to this server only. Nothing here stores a token.
Sign in to use your browser session, or paste a personal access token below.
PATCH changes your profile. The full list of endpoints and fields is in the API docs.
Sign in with Unit
Unit is an OpenID Connect provider: code flow with PKCE (S256),
signed RS256 ID tokens and a /userinfo endpoint. Register an
integration on your profile page with your callback URL,
or use the OIDC demo with these credentials:
| Client ID | cli_unitdemo
|
|---|---|
| Client secret |
|
| Redirect URI | https://unit.plera.net/demo/callback
|
1. Send the user to Unit (browser)
Put this in your app's JavaScript. Keep the verifier for the callback —
state and PKCE are both required.
async function signInWithUnit() {
const bytes = crypto.getRandomValues(new Uint8Array(32));
const verifier = btoa(String.fromCharCode(...bytes))
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier));
const challenge = btoa(String.fromCharCode(...new Uint8Array(digest)))
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
const state = verifier;
sessionStorage.setItem('unit_verifier', verifier);
sessionStorage.setItem('unit_state', state);
const params = new URLSearchParams({
response_type: 'code', client_id: 'cli_yourid',
redirect_uri: location.origin + '/callback',
scope: 'openid profile email', state,
code_challenge: challenge, code_challenge_method: 'S256'
});
location.href = 'https://unit.plera.net/authorize?' + params;
}
2. Exchange the code and read the profile (Python)
import json, urllib.parse, urllib.request
UNIT = 'https://unit.plera.net'
CLIENT_ID, SECRET = 'cli_yourid', 'your_secret'
REDIRECT = 'https://app.example.com/callback'
VERIFIER = 'the same code_verifier you hashed in step 1'
def exchange(code):
data = urllib.parse.urlencode({
'grant_type': 'authorization_code', 'code': code,
'client_id': CLIENT_ID, 'client_secret': SECRET,
'redirect_uri': REDIRECT, 'code_verifier': VERIFIER,
}).encode()
req = urllib.request.Request(UNIT + '/token', data=data,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
with urllib.request.urlopen(req, timeout=20) as response:
return json.load(response)
def profile(access_token):
req = urllib.request.Request(UNIT + '/userinfo',
headers={'Authorization': 'Bearer ' + access_token})
with urllib.request.urlopen(req, timeout=20) as response:
return json.load(response)
# tokens = exchange(request.args['code'])
# claims = profile(tokens['access_token']) -> sub, name, email, ...
2. Exchange the code and read the profile (JavaScript)
Do this on your server in a real app — never put a client secret in browser code. The snippet is here to show the wire format.
const params = new URLSearchParams(location.search);
const code = params.get('code'), state = params.get('state');
if (state !== sessionStorage.getItem('unit_state')) throw new Error('state mismatch');
const body = new URLSearchParams({
grant_type: 'authorization_code', code,
client_id: 'cli_yourid', client_secret: 'your_secret',
redirect_uri: location.origin + '/callback',
code_verifier: sessionStorage.getItem('unit_verifier')
});
const res = await fetch('https://unit.plera.net/token', {
method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body
});
const tokens = await res.json();
const claims = await (await fetch('https://unit.plera.net/userinfo', {
headers: {Authorization: 'Bearer ' + tokens.access_token}
})).json();
A complete, dependency-free app is in
examples/sign-in-with-unit/ in the source tree. Discovery:
/.well-known/openid-configuration
Authentication
Send a personal access token in one of these forms:
Authorization: Bearer unit_... Authorization: token unit_...
Create tokens on your profile page or via the API:
curl -X POST https://unit.plera.net/api/tokens \
-H "Authorization: Bearer unit_..." \
-H "Content-Type: application/json" \
-d '{"name": "laptop", "scopes": ["read"]}'
The raw token is returned once and stored only as a hash.
Revoke it at any time from the profile page or with
DELETE /api/tokens/{id}.
Scopes
| Scope | Grants |
|---|---|
read | Read your profile, public pages and clients. |
write | Everything read does, plus update your
profile and upload an avatar. |
admin | Everything write does, plus
administrative endpoints. |
Each scope implies the ones before it. A token is rejected with
403 when its scope is too low. Tokens can never change your password,
email address, or create/revoke tokens — those actions require a browser session.
Rate limits
| Caller | Limit | Configured by |
|---|---|---|
| Token or signed-in user | 5000 requests / hour | UNIT_API_RATE_LIMIT |
| Anonymous (no token) | 600 requests / hour | UNIT_API_RATE_LIMIT_ANON |
| Token creation | 30 tokens / hour, 50 active | fixed |
Every /api/ response carries:
X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4998 X-RateLimit-Reset: 1735689600 X-OAuth-Scopes: read write
X-OAuth-Scopes is present for token callers.
When you exceed the limit you get 429 with a Retry-After
header naming the seconds to wait.
CORS
Set UNIT_CORS_ORIGINS (comma separated) to allow specific browser
origins with credentials:
UNIT_CORS_ORIGINS=https://app.example.com,http://localhost:3000
When unset, any origin may call the API without cookies — use a token instead. Server-to-server calls are unaffected either way.
Examples
Read your own profile:
curl https://unit.plera.net/api/users/me \ -H "Authorization: Bearer unit_..."
Update it (requires write):
curl -X PATCH https://unit.plera.net/api/users/me \
-H "Authorization: Bearer unit_..." \
-H "Content-Type: application/json" \
-d '{"bio": "Hello"}'
List and revoke tokens:
curl https://unit.plera.net/api/tokens -H "Authorization: Bearer unit_..." curl -X DELETE https://unit.plera.net/api/tokens/1 -H "Authorization: Bearer unit_..."
Full endpoint list: /docs · schema: /developer/openapi.json