API Documentation
OpenAI-compatible API. Drop-in replacement — just change your base URL.
Short answer
APIVAI is a pay-as-you-go API gateway for Claude and GPT. One API key works in two formats: Anthropic Messages at https://api.apivai.com (Claude Code, Anthropic SDK; endpoint /v1/messages) and OpenAI at https://api.apivai.com/v1 (endpoints /v1/chat/completions, /v1/responses and /v1/models). Send the key as Authorization: Bearer or x-api-key, pick a model ID from GET /v1/models, and use streaming for long tasks.
https://api.apivai.com/v1— OpenAI-compatible API endpoint (Claude + GPT)https://api.apivai.com— Anthropic Messages format (Claude Code, Anthropic SDK), no /v1Get Started in 2 Minutes
APIVAI provides an API proxy compatible with both Anthropic and OpenAI formats. Just set two environment variables and you're ready to go.
1. Get your API Key
Sign up at apivai.com and top up, then create an API key on the Dashboard page.
2. Set your Base URL
3. Start using
If ANTHROPIC_API_KEY is already set in your shell, remove it first, or it is used instead of your APIVAI key: unset ANTHROPIC_API_KEY (PowerShell: Remove-Item Env:ANTHROPIC_API_KEY).
Claude Messages API (Native Anthropic Format)
Use the standard Anthropic Messages API. Just change the base_url and api_key.
https://api.apivai.comPython (Anthropic SDK)
cURL (Messages API)
cURL (Streaming)
List Models
claude-fable-5-1Most Powerfulclaude-opus-5-5Powerfulclaude-sonnet-5-5Best Valueclaude-sonnet-4-6Popularclaude-haiku-4-5FastestAuthentication
All API requests require an API key, passed as a Bearer token in the Authorization header (Authorization: Bearer YOUR_API_KEY). The x-api-key header, which the Anthropic SDK and Claude Code send, works as well. Get your API key from the Dashboard after logging in.
Using OpenAI SDK
POST /v1/chat/completions
Creates a chat completion. Compatible with OpenAI's chat completions format.
Request Body
Available Models
All models (Claude + GPT) can be called through the same endpoint, /v1/chat/completions. Claude models also work through /v1/messages (Anthropic format), and GPT models through /v1/responses (used by Codex CLI). Use the model ID in your API requests.
Streaming (SSE)
Set stream: true to receive Server-Sent Events for real-time token delivery.
Use streaming for long tasks (long thinking, large outputs): a request without streaming that takes more than 100 seconds to answer is cut off on the way; with streaming the connection stays open however long the model thinks.
Editors & Agents
These tools accept an OpenAI-compatible base URL and key. Pick the model from GET /v1/models, and start with a small task — agentic tools send a lot of tokens.
Codex CLI
Codex relies on the Responses API (/v1/responses), which APIVAI exposes, so tool calls and streaming work as expected.
Cline
| Field | Value |
|---|---|
| API Provider | OpenAI Compatible |
| Base URL | https://api.apivai.com/v1 |
| API Key | Your APIVAI API key |
| Model | An ID from GET /v1/models |
Aider
A cheaper model is usually enough for routine edits; switch to a stronger one only for harder changes.
Continue.dev
Edit ~/.continue/config.yaml (Windows: %USERPROFILE%\.continue\config.yaml; the older config.json format is deprecated) and add a model entry. With provider: openai, apiBase ends in /v1 and the same entry works for Claude and GPT model IDs. Full walkthrough: Continue setup guide.
Before you start
- The base URL contains /v1 exactly once.
- The selected model appears in the current model list.
- The tool process can actually read the key (environment or settings).
- Keys stay out of workspace files, shared configs and screenshots.
More detail: OpenAI-Compatible API · Claude API Proxy
FAQ
Where do I get an API key?
How do I choose a model?
Which base URL should I use?
Can I use Cursor or other editor agents?
Can I call the API directly from browser code?
What should I do if my key is exposed?
Why are output tokens higher than the text I received?
Why do the examples use a placeholder key?
Troubleshooting
Work through these in order: configuration, model discovery, then a minimal chat request. Keep the request small until the endpoint, key and model all work.
1. Check model discovery
If this fails, fix authentication or the base URL before testing anything else.
2. Send a minimal chat request
Status codes
| Status | Common cause | What to check |
|---|---|---|
| 401 | Missing or invalid key | The key is set and sent as Authorization: Bearer <key>. |
| 402 insufficient_quota | The key has no budget left | Add budget to the key in the Dashboard, or top up your balance. |
| 403 | The account that owns the key is disabled | Contact support (support@apivai.com). |
| 404 | Wrong base URL or path | /v1 appears exactly once; the path is /messages, /chat/completions, /responses or /models. |
| 408 | Network or client timeout | Retry from the same shell, then try another network. |
| 429 | Rate limit or balance limit reached | Reduce concurrency, retry with backoff, check your balance. |
| 503 / 529 overloaded_error | The model is temporarily overloaded | Retry after a few seconds, with backoff between attempts. |
| 524 | A non-streaming request ran longer than about 100 seconds | Use "stream": true for long answers (large max_tokens, long reasoning). Streamed answers are not cut off; a retried non-streamed request is billed again. |
| 5xx | Server-side error | Retry after a short delay and note the timestamp for support. |
Every error code with its causes and fixes: Claude API error codes.
Why do I get 404 Not Found?
The final address is wrong, usually because /v1 is missing, extra or doubled. Requests must reach https://api.apivai.com/v1/messages, /v1/chat/completions, /v1/responses or /v1/models; Claude Code and the Anthropic SDK take https://api.apivai.com, OpenAI-style tools take https://api.apivai.com/v1.
Why does my key return 401?
The key is missing, mistyped, deleted, or not visible to the process that sends the request. With Claude Code, an ANTHROPIC_API_KEY left in your shell takes priority over your APIVAI key; unset it.
Why do I get 402 or 429?
402 insufficient_quota means the key's budget is used up: add budget to the key or top up your balance. 429 means too many requests at once (60 per minute per key by default) or no budget left: slow down and retry with backoff.
Why does a long request fail with 524?
A request without streaming that takes more than about 100 seconds is cut off on the way. Send long requests with "stream": true; streamed answers are not cut off.
Why does streaming print nothing?
Usually the client is not reading the response as a stream, or it skips chunks that carry no text. Check these:
- The request body includes "stream": true.
- Your HTTP client reads the body incrementally.
- The non-streaming request works — this separates parsing problems from auth or model problems.
- Some chunks carry only metadata or a finish reason, not text.
Why is the reply empty or cut off?
Thinking is on by default and its tokens count toward the output limit. With a small max_tokens the model can spend the whole limit on thinking and return no text, while the request is still billed.
- The finish reason is "length" (or stop_reason is "max_tokens") — the limit was reached.
- Set max_tokens to 4096 or higher; for long answers or code, 8192 or higher.
- You only pay for tokens actually used, so a higher limit does not cost more by itself.
Why does curl return a JSON parse error?
Shell quoting is a frequent source of JSON parse errors. Put the body in a file and send it with --data @body.json.
Before contacting support
- HTTP status code and endpoint path (never the key).
- Approximate time and timezone.
- Request and response bodies with secrets and private content removed.
- Runtime and version, such as Python or Node.js.
Tools Integration
APIVAI works as a drop-in replacement for official APIs. Just change the base URL in your favorite tool.
Claude Code
Set two environment variables before running Claude Code.
Cursor
Go to Cursor Settings → Models → Override OpenAI Base URL:
OpenAI Python SDK
Use the OpenAI SDK with our base URL for all models including Claude.
Anthropic Python SDK
Use the official Anthropic SDK — just change the base URL.
cURL
Direct API call with curl.