Endpoint reference
All endpoints are relative to https://api.cerebrafi.xyz/v1. Amounts are USD, and token prices are per million tokens.
POST/v1/chat/completions
Create a chat completion. OpenAI-compatible, with streaming and a per-request spend cap.
Requires API key| Parameter | Type | Description |
|---|---|---|
modelrequired | string | Model id such as deepseek/deepseek-flash. See Models. |
messagesrequired | array | Conversation in OpenAI message format. At least one message. |
stream | boolean | Return server-sent events. Usage is requested from the provider automatically. |
max_tokens | integer | Upper bound on output tokens. Defaults to 8,192 and is capped at the model's maximum. max_completion_tokens is also accepted. |
max_cost | number | string | Maximum USD this request may cost, for example 0.02. Also accepted as the x-max-cost header. |
… | any | Any other field (temperature, top_p, tools, response_format) is forwarded to the provider. |
curl https://api.cerebrafi.xyz/v1/chat/completions \
-H "Authorization: Bearer $CEREBRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-flash",
"messages": [{ "role": "user", "content": "Say hello in one sentence." }],
"max_cost": 0.02
}'{
"id": "chatcmpl-cerebra-0b5f6f1e-3a52-4f2c-9c1b-7f3d1c1e2a10",
"object": "chat.completion",
"model": "deepseek/deepseek-flash",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "Hello!" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 9, "completion_tokens": 3, "total_tokens": 12, "cost": 0.0000063 }
}The response also carries these headers:
| Parameter | Type | Description |
|---|---|---|
x-request-id | string | Request id, identical to the id in the body. |
x-cerebra-cost | decimal | Exact USD charged for this request. |
x-cerebra-balance | decimal | Your USD balance after the request. |
The gateway reserves the worst-case cost before calling the provider. The budget is the text-smer of your balance and max_cost. If the worst case exceeds the budget, max_tokens is lowered to the largest value that fits. If not even one output token fits, the request fails with 402 max_cost_exceeded (or insufficient_balancewhen the balance is the limit). The unused reservation is refunded when the request settles.
With stream: true the response is text/event-stream. Chunks follow the OpenAI format and end with data: [DONE]. The final chunk includes usage with cost. If the client disconnects, the request settles on the tokens produced so far.
data: {"id":"chatcmpl-cerebra-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"}}]}
data: {"id":"chatcmpl-cerebra-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":3,"cost":0.0000063}}
data: [DONE]GET/v1/models
List models with context size and USD prices per million tokens.
No authcurl https://api.cerebrafi.xyz/v1/models{
"object": "list",
"data": [
{
"id": "deepseek/deepseek-flash",
"object": "model",
"owned_by": "deepseek",
"name": "DeepSeek V4.1 Flash",
"context_length": 1000000,
"max_output_tokens": 384000,
"available": true,
"pricing": { "currency": "USD", "unit": "1M tokens", "input": 0.3, "cached_input": 0.006, "output": 1.2 }
}
]
}GET/v1/key
Balance and lifetime totals for the wallet that owns the key.
Requires API keycurl https://api.cerebrafi.xyz/v1/key \
-H "Authorization: Bearer $CEREBRA_API_KEY"{
"address": "0x1234…abcd",
"epoch": 0,
"balance": "4.812500",
"total_credited": "10.000000",
"total_spent": "5.187500"
}Amounts are decimal strings in USD with six decimals.
GET/v1/usage
Recent requests for the key, newest first, with tokens and exact cost.
Requires API key| Parameter | Type | Description |
|---|---|---|
limit | integer | Query parameter. Number of records, 1 to 200. Defaults to 50. |
curl "https://api.cerebrafi.xyz/v1/usage?limit=2" \
-H "Authorization: Bearer $CEREBRA_API_KEY"{
"object": "list",
"data": [
{
"id": "chatcmpl-cerebra-0b5f6f1e-…",
"model": "deepseek/deepseek-flash",
"prompt_tokens": 9,
"completion_tokens": 3,
"cost": "0.000006",
"status": "ok",
"created_at": 1790000000
}
]
}status is ok, aborted when the client disconnected, or the same value with an _estimated suffix when the provider sent no usage and tokens were estimated.
GET/v1/keys/message
The exact message to sign to derive the key for an epoch.
No auth| Parameter | Type | Description |
|---|---|---|
epoch | integer | Query parameter. Key epoch, defaults to 0. |
curl "https://api.cerebrafi.xyz/v1/keys/message?epoch=0"{
"chain_id": 99901,
"epoch": 0,
"message": "Cerebra API key · chain 99901 · epoch 0"
}POST/v1/keys
Verify a wallet signature and return the derived API key. Registering a higher epoch revokes older keys.
No auth| Parameter | Type | Description |
|---|---|---|
addressrequired | string | Wallet address that signed the message. |
signaturerequired | string | 0x-prefixed personal_sign signature over the key message. |
epoch | integer | Key epoch. Defaults to 0. |
curl -X POST https://api.cerebrafi.xyz/v1/keys \
-H "Content-Type: application/json" \
-d '{ "address": "0xYourAddress", "signature": "0x…", "epoch": 0 }'{ "key": "cerebra_0123456789abcdef0123456789abcdef0123456789abcdef", "epoch": 0, "address": "0xyouraddress" }See Authentication for the full flow. Failures: invalid_signature (401), epoch_revoked (409), invalid_address (400).
GET/v1/accounts/{address}
Public balance and deposit history for a wallet. Deposits are on-chain, so balances are public too.
No authcurl https://api.cerebrafi.xyz/v1/accounts/0x1234567890abcdef1234567890abcdef12345678{
"address": "0x1234…5678",
"balance": "4.812500",
"total_credited": "10.000000",
"total_spent": "5.187500",
"key_epoch": 0,
"deposits": [
{
"id": "42",
"tx_hash": "0x…",
"block_number": "123456",
"payer": "0x…",
"cerebra": "20000",
"usd": "10.000000",
"price": "0.0005"
}
]
}GET/health
Liveness and indexer progress. Served at the root, not under /v1.
No auth{ "ok": true, "chain_id": 99901, "indexed_block": "123460" }Need something else?