Gapnil API documentation
Gapnil is wire-compatible with the OpenAI and Anthropic APIs. If your code already uses one of those SDKs, switching means changing the base URL and the key.
Quickstart
- Create an account and add credit under Billing.
- Create a key under API keys. It starts with
tf_live_and is only shown once. - Point your client at the base URL below.
https://gapnil.com/v1
https://gapnil.com # Anthropic SDKs append /v1/messages themselves
from openai import OpenAI client = OpenAI(base_url="https://gapnil.com/v1", api_key="tf_live_...") r = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{"role": "user", "content": "Say hi"}], ) print(r.choices[0].message.content)
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://gapnil.com/v1", apiKey: process.env.GAPNIL_API_KEY }); const r = await client.chat.completions.create({ model: "deepseek-v4.1-flash", messages: [{ role: "user", content: "Say hi" }], });
curl https://gapnil.com/v1/chat/completions \ -H "Authorization: Bearer $GAPNIL_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"Say hi"}]}'
Authentication
Send your key as Authorization: Bearer tf_live_…. The x-api-key header is accepted as well, the way Anthropic SDKs send it. Keys are stored hashed. Revoking a key in the dashboard takes effect on the next request.
Endpoints
| Method & path | Purpose |
|---|---|
POST /v1/chat/completions | OpenAI Chat Completions, including tools, vision and streaming |
POST /v1/responses | OpenAI Responses API (stateless) |
POST /v1/completions | Legacy text completions |
POST /v1/messages | Anthropic Messages |
POST /v1/messages/count_tokens | Token count estimate (free) |
POST /v1/embeddings | Text embeddings |
POST /v1/rerank, /v2/rerank | Document reranking, for example with rerank-v3.5 |
POST /v1/images/generations, /v1/images/edits | Image generation and editing |
POST /v1/videos/generations | Video generation (blocks until complete) |
POST /v1/audio/speech, /transcriptions, /translations | Text-to-speech and speech-to-text |
POST /v1/uploads, DELETE /v1/uploads/{id} | Temporary image uploads for vision prompts |
GET /v1/models | Catalog with Gapnil prices (no key needed) |
Choosing a model
Pass any id from the catalog as model. Vendor-prefixed aliases such as anthropic/claude-opus-5 also resolve. Each catalog entry lists the endpoints it supports in supported_endpoints.
Streaming
Set "stream": true. Events are relayed as they arrive: chat.completion.chunk for Chat Completions, Anthropic's message_start … message_stop for Messages. The last chunk before [DONE] has an empty choices array and carries the usage, whether or not you pass stream_options.include_usage.
Billing & usage
Requests are paid from your prepaid wallet at the rates in the catalog. Input and output token rates are never above the model maker's own list price. Most non-streamed responses include the exact charge, in US dollars. The cost, request_id and billing fields are left out when the charge is not final yet, so read them as optional and use Usage in the dashboard for the settled figure:
{
"usage": { "prompt_tokens": 21, "completion_tokens": 9, "cost": 0.000012 },
"request_id": "req_…",
"billing": { "status": "settled", "billed_cost_usd": "0.000012", "currency": "USD" }
}Each response also carries an x-tokenfly-request-id header that matches the entry under Usage in the dashboard. Streamed Chat Completions are charged from their token counts first, then corrected to the final settled figure a few seconds later.
Errors
Errors use the OpenAI envelope, {"error": {"message", "type", "code"}}, or the Anthropic one on /v1/messages.
| Status | Meaning |
|---|---|
| 400 / 422 | Invalid request, such as a malformed body or a model called on an endpoint it does not support |
| 401 | Missing, invalid or revoked API key |
| 402 | Wallet is empty. Add credit to continue. |
| 404 | Unknown model id or endpoint path |
| 429 | Rate or concurrency limit. Honour Retry-After. |
| 502 / 503 | Provider capacity issue. Retry with exponential backoff. |
Limits
- Request bodies: up to 20 MB.
Content-Encoding: gzipis accepted. A model's context window is usually the tighter limit. - Default rate limit of 600 requests per minute per key, and 50 concurrent requests per account. Contact us to raise either.
- The realtime (WebSocket) endpoint
/v1/realtimeis not available yet.
Data handling
Gapnil stores request metadata needed for billing: time, endpoint, model, token counts, cost, latency and status. Prompts and completions are relayed in memory and never written to our database or logs.