API endpoints and credentials
Base URL: https://router-api.0g.ai/v1
This page answers one question: which credential does this endpoint take. Parameters and response schemas are not repeated here.
Endpoint map
Section titled “Endpoint map”| Endpoint | What it does | Credential |
|---|---|---|
POST /v1/chat/completions |
OpenAI-compatible chat, streaming and tool calling | sk- |
POST /v1/messages |
Anthropic Messages-compatible surface over the same providers | sk- |
POST /v1/images/generations |
Image generation, JSON body | sk- |
POST /v1/images/edits |
Image editing, multipart; routing is header-only | sk- |
POST /v1/async/images/generations |
Async image generation | sk- |
POST /v1/async/images/edits |
Async image editing, multipart | sk- |
POST /v1/audio/transcriptions |
Speech-to-text, multipart; routing is header-only | sk- |
GET /v1/models |
Live model catalog | none |
GET /v1/providers |
Endpoints serving a model | none |
GET /v1/account/balance |
Router ledger balance | mk- with account:read |
GET /v1/account/funds |
Aggregated wallet view | mk- with account:read |
GET /v1/account/usage/stats |
Usage and spend | mk- with account:read |
GET/POST /v1/api-keys |
List and create sk- keys |
mk- with keys:read / keys:create |
PATCH/DELETE /v1/api-keys/:id |
Update or revoke a sk- key |
mk- with keys:manage |
/v1/management-keys |
Manage mk- keys |
Wallet session in the Console only |
Every inference response carries an x_0g_trace block with request_id, the serving provider address, and the exact billing cost, plus the X-RateLimit-* response headers. All inference endpoints accept the X-0G-Provider-* routing headers — see Provider Routing Headers. Catalog responses are described in Model Catalog.
Two credentials
Section titled “Two credentials”Both types are issued in the Console at https://pc.0g.ai/ and both travel in the same header.
Authorization: Bearer sk-<YOUR_API_KEY>| Type | What it does | Scopes | Expiry |
|---|---|---|---|
sk- API key |
Calls inference endpoints. Billed against your deposit. | No scope concept | Valid until revoked |
mk- management key |
Reads account state and manages sk- keys. Never billed. |
account:read, keys:read, keys:create, keys:manage |
Does not expire; rotate deliberately |
Store them in ZG_API_KEY and ZG_MANAGEMENT_KEY, never in a repository or a browser bundle.
An mk- key cannot call inference, and it cannot manage other mk- keys — that last one requires a wallet session in the Console.
Per-key trust mode
Section titled “Per-key trust mode”A sk- key can carry a trust mode, set in the Console or by passing "trust_mode": "private" to POST /v1/api-keys with an mk- key. It applies to every request made with that key and cannot be overridden by request headers. See Trust Modes.
Key lifecycle
Section titled “Key lifecycle”- Keys are created in the Console at https://pc.0g.ai/. A
sk-key can also be created throughPOST /v1/api-keyswith anmk-key holdingkeys:create. Step-by-step: Manage API keys. - The secret is shown once at creation. If you lose it, issue a new key; it cannot be recovered.
- Revocation is immediate and applies everywhere. Subsequent requests get
401 invalid_api_keywith no grace period, so roll the replacement before you revoke. - Management keys do not expire. Rotation is the control, so rotate on a schedule and whenever an operator leaves.
- Each
mk-key recordslast_used_atandlast_source_ipfor auditing. Both are coalesced to a 60-second window, so a burst of calls updates them once.
Authentication errors
Section titled “Authentication errors”| Code | Status | Meaning |
|---|---|---|
missing_authorization |
401 | No Authorization header |
invalid_api_key |
401 | The key does not exist or is malformed |
invalid_api_key |
401 | Unknown, malformed, or revoked key |
access_denied |
403 | The credential is not allowed to perform this action |
insufficient_scope |
403 | The credential lacks the required scope |
api_key_not_found |
404 | The referenced key does not exist |
Full table and retry guidance: Error Codes.
Full reference
Section titled “Full reference”Request parameters, response schemas, and the full authentication model are documented in the Router reference in the 0G Documentation: https://docs.0g.ai/concepts/compute. This page carries only the credential map and the behaviors the recipes here depend on.
Related
Section titled “Related”- Manage API keys — creating, scoping, and revoking keys in the Console
- Provider Routing Headers — the routing and response headers every inference endpoint uses
- Error Codes — status, type, code, and what is retryable
- Model Catalog — what
/v1/modelsand/v1/providersreturn