API documentation
Everything you need to make your first call. Samples use your own base URL and models when you are signed in.
Quick start
1. Buy a plan on the Plans page. Your first API key is created for you: open API keys and press Show key (a key can be seen only once). 2. Call the API at the base URL below. 3. Send a first request.
| Base URL |
|---|
| /v1 |
curl /v1/chat/completions \
-H "Authorization: Bearer gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "your-model", "messages": [{"role": "user", "content": "Hello!"}]}'Authentication
Send your API key in the Authorization header as a bearer token. The Anthropic format (/messages) also accepts the key in the x-api-key header, so an Anthropic SDK needs only a new base URL.
curl /v1/models \ -H "Authorization: Bearer gk_live_..."
Chat completions
POST /chat/completions is the OpenAI chat format. Set "stream": true to receive the answer as server-sent events. When your quota has room for less than the largest possible answer, GateKeeper lowers max_tokens for you so the answer fits what you have left.
Streaming
curl -N /v1/chat/completions \
-H "Authorization: Bearer gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "your-model", "stream": true, "messages": [{"role": "user", "content": "Hello!"}]}'Responses
POST /responses is the OpenAI Responses format, streaming or not. Tokens are counted from the usage the provider reports. Only tools that your own code runs (function tools) can be used; tools the provider runs itself, such as web search, are refused.
curl /v1/responses \
-H "Authorization: Bearer gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "your-model", "input": "Hello!"}'Messages (Anthropic)
POST /messages is the Anthropic Messages format, passed through to an Anthropic provider as it is. max_tokens is required. Cache tokens count as input tokens. Use a model that your plan offers for this format.
curl /v1/messages \
-H "x-api-key: gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "your-claude-model", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello!"}]}'Embeddings
POST /embeddings turns text into vectors. It is billed by the input tokens only (times the model's input weight). The input is a string or a list.
curl /v1/embeddings \
-H "Authorization: Bearer gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "your-embedding-model", "input": "Hello!"}'Images
POST /images/generations creates images. Each image costs a fixed number of tokens from your plan, set per model. n is 1 to 10. If your quota cannot cover all n images the request is refused with 402 before anything is generated.
curl /v1/images/generations \
-H "Authorization: Bearer gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "your-image-model", "prompt": "A red cat", "n": 1}'Models
GET /models lists the models your key may call. Each entry has a kind: chat, embedding or image. A model can be used only on the endpoint of its kind.
curl /v1/models \ -H "Authorization: Bearer gk_live_..."
Quota
GET /quota shows the plan behind your key and what is left. Use it to warn your users before the quota ends.
curl /v1/quota \ -H "Authorization: Bearer gk_live_..."
| Field | Meaning |
|---|---|
| plan_name | The plan's name. |
| status | active, exhausted, expired or cancelled. |
| tokens_total | Tokens in the plan. null when the plan has only a time limit. |
| tokens_used | Tokens used so far. |
| tokens_reserved | Tokens held by requests that are still running. |
| tokens_remaining | What is left (total minus used minus held). |
| expires_at | When access ends, or null. |
| models | Names of the models of the plan. |
| api_base | The base URL of this API. |
Errors
Errors use the OpenAI shape: {"error": {"message", "type", "code"}}. The HTTP status tells what to do next.
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_request_error | The request is not valid, or the model is of another kind than the endpoint. |
| 401 | invalid_api_key / key_expired | The key is wrong, revoked or expired. |
| 402 | quota_exceeded / key_limit_exceeded | The plan's quota is used up or expired, or this key reached its own token limit. |
| 403 | forbidden | The model is not in your plan, or this key may not use that model or your IP address. |
| 404 | not_found | The model does not exist. |
| 429 | rate_limit_exceeded | Too many requests. Wait for Retry-After seconds. |
| 502 | upstream_error | The model provider failed. Nothing is billed. Try again. |
curl -i /v1/chat/completions \
-H "Authorization: Bearer gk_live_..." \
-H "Content-Type: application/json" \
-d '{"model": "no-such-model", "messages": [{"role": "user", "content": "Hi"}]}'Rate limits
When your plan or key has a requests-per-minute limit, answers carry the headers below. A 429 also carries Retry-After in seconds. The lower of the plan's and the key's limit applies.
| Header | Meaning |
|---|---|
| x-ratelimit-limit-requests | Requests allowed per minute. |
| x-ratelimit-remaining-requests | Requests left in this minute. |
| x-ratelimit-reset-requests | When the window resets, for example 12s. |
| Retry-After | On a 429: seconds to wait. |
How tokens are counted
Before a request runs, GateKeeper holds the tokens it could use: an estimate of your input plus the largest answer allowed. When the answer is done, the hold is replaced by the real usage the provider reported. If the call fails, the hold is released and nothing is billed.
Billed tokens are the input tokens times the model's input weight plus the output tokens times its output weight (both 1 unless set otherwise), rounded up. Images cost a fixed number of tokens each.
SDK setup
Any OpenAI-compatible SDK works. Set the base URL and the key, and nothing else changes.
export OPENAI_BASE_URL=/v1 export OPENAI_API_KEY=gk_live_...