> Documentation index: https://quotax.sh/llms.txt. Agents: https://quotax.sh/skill.md is the setup guide written for you.

# quotax.sh quickstart

quotax.sh speaks the Anthropic and OpenAI APIs. Swap the base URL, use your `qtx-` key, and your usual tools just work.

## Overview

The base URL is `https://quotax.sh`. Send your key in the `Authorization: Bearer` or `x-api-key` header. Create keys in the dashboard at https://quotax.sh/app/keys, or let an agent get one with the device flow (https://quotax.sh/agents.md).

| Endpoint | Description |
| --- | --- |
| `POST /v1/messages` | Anthropic Messages (streaming and non-streaming) |
| `POST /v1/messages/count_tokens` | Anthropic-style token counting |
| `POST /v1/chat/completions` | OpenAI Chat Completions |
| `POST /v1/responses` | OpenAI Responses (used by Codex) |
| `GET /v1/models` | Models your key can use |

- Anthropic SDKs and Claude Code: base URL `https://quotax.sh` (no `/v1`).
- OpenAI SDKs, Codex and most other tools: base URL `https://quotax.sh/v1`.
- Every model in the catalog works on all three APIs.

Find model ids on the models page (https://quotax.sh/models/) or, as JSON, at `GET https://quotax.sh/api/public/catalog` (no key needed). `GET /v1/models` lists the ids your key may call. Free keys can only call free ($0) models or models on a 100% promotion for the Free plan. The examples below use `<model-id>`: replace it with a real id, and don't hardcode ids in code that outlives today's catalog.

## Claude Code

Set the base URL and key, map the models to catalog ids, then run `claude` as usual. Every model in the catalog works, including non-Anthropic models.

```sh
export ANTHROPIC_BASE_URL=https://quotax.sh
export ANTHROPIC_AUTH_TOKEN=$QUOTAX_API_KEY

# Default model, and the ids behind Claude Code's opus, sonnet and haiku aliases
# (subagents and background tasks use them; unmapped, those calls fail with 404)
export ANTHROPIC_MODEL=<model-id>
export ANTHROPIC_DEFAULT_OPUS_MODEL=<model-id>
export ANTHROPIC_DEFAULT_SONNET_MODEL=<model-id>
export ANTHROPIC_DEFAULT_HAIKU_MODEL=<model-id>

claude
```

For a persistent setup, add this to `~/.claude/settings.json`. The `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY` variable lets the `/model` command list models from quotax.sh.

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://quotax.sh",
    "ANTHROPIC_AUTH_TOKEN": "qtx-your-key",
    "ANTHROPIC_MODEL": "<model-id>",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "<model-id>",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "<model-id>",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "<model-id>",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}
```

Keep this file at user level (`~/.claude/`), never in a repository. To keep the key out of the file entirely, use `"apiKeyHelper": "sed -n 's/^QUOTAX_API_KEY=//p' \"${QUOTAX_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/quotax}/env\""` instead of `ANTHROPIC_AUTH_TOKEN` (the init script writes that file).

## Codex CLI

Codex only uses the Responses API. Register quotax.sh as a provider with `wire_api = "responses"` in `~/.codex/config.toml`:

```toml
model = "<model-id>"
model_provider = "quotax"

[model_providers.quotax]
name = "quotax.sh"
base_url = "https://quotax.sh/v1"
env_key = "QUOTAX_API_KEY"
wire_api = "responses"
```

```sh
export QUOTAX_API_KEY=qtx-your-key
codex

# or pick a different model for one session
codex --model <model-id>
```

## OpenAI SDK

Point `base_url` at `https://quotax.sh/v1`. Both Chat Completions and Responses are supported.

Python (`pip install openai`):

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://quotax.sh/v1",
    api_key=os.environ["QUOTAX_API_KEY"],
)

# Chat Completions
chat = client.chat.completions.create(
    model="<model-id>",
    messages=[{"role": "user", "content": "Hello! Give me a short intro to Hanoi."}],
)
print(chat.choices[0].message.content)

# Responses API
resp = client.responses.create(model="<model-id>", input="Write a fun programming riddle.")
print(resp.output_text)
```

TypeScript (`npm i openai`):

```ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://quotax.sh/v1",
  apiKey: process.env.QUOTAX_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "<model-id>",
  messages: [{ role: "user", content: "Summarize The Tale of Kieu in 3 sentences." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

## Anthropic SDK

For the Anthropic SDK, the base URL is `https://quotax.sh` (without `/v1`).

Python (`pip install anthropic`):

```python
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://quotax.sh",
    api_key=os.environ["QUOTAX_API_KEY"],
)

message = client.messages.create(
    model="<model-id>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain goroutines in simple terms."}],
)
print(message.content[0].text)
```

TypeScript (`npm i @anthropic-ai/sdk`):

```ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://quotax.sh",
  apiKey: process.env.QUOTAX_API_KEY,
});

const stream = client.messages.stream({
  model: "<model-id>",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Write a debounce function in TypeScript." }],
});
stream.on("text", (text) => process.stdout.write(text));
await stream.finalMessage();
```

## curl

Anthropic Messages:

```sh
curl https://quotax.sh/v1/messages \
  -H "x-api-key: $QUOTAX_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "<model-id>",
    "max_tokens": 512,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

OpenAI Chat Completions (stream):

```sh
curl https://quotax.sh/v1/chat/completions \
  -H "Authorization: Bearer $QUOTAX_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "<model-id>",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": true
  }'
```

OpenAI Responses:

```sh
curl https://quotax.sh/v1/responses \
  -H "Authorization: Bearer $QUOTAX_API_KEY" \
  -H "content-type: application/json" \
  -d '{"model": "<model-id>", "input": "Hello"}'
```

Count tokens (not billed):

```sh
curl https://quotax.sh/v1/messages/count_tokens \
  -H "x-api-key: $QUOTAX_API_KEY" \
  -H "content-type: application/json" \
  -d '{"model": "<model-id>", "messages": [{"role": "user", "content": "Hello"}]}'
```

List models:

```sh
curl https://quotax.sh/v1/models -H "Authorization: Bearer $QUOTAX_API_KEY"
```

`/v1/models` answers in Anthropic shape when you send `anthropic-version` or `x-api-key`, otherwise in OpenAI shape.

## Errors & limits

Errors are returned in the format of the protocol you call (Anthropic or OpenAI). Daily limits reset on Vietnam time (GMT+7, 00:00 Asia/Ho_Chi_Minh).

| Status | When | Fix |
| --- | --- | --- |
| 401 | The API key is wrong, deleted or disabled (`authentication_error`, OpenAI code `invalid_api_key`). | Check your key on the API keys page. |
| 402 | A pay-per-token key's wallet cannot cover the request's estimated maximum cost (Anthropic `billing_error`; OpenAI `invalid_request_error` with code `insufficient_quota`). | Top up at https://quotax.sh/app/billing (VietQR bank transfer), or lower `max_tokens`. |
| 403 | The model is not included in the key's plan, or a Free key called a model that is not free right now (`permission_error`). | Use a model that is currently free, or create a pay-per-token key. |
| 429 | The key exceeded its requests-per-minute, concurrent request or daily limit, or a promotion's daily quota (`rate_limit_error`). | Respect the `Retry-After` header, reduce load, or buy a daily plan. |
| 400, 404, 413 | Invalid request, unknown model (`not_found_error`), unknown endpoint, or content too large. | Fix the request; errors are returned in the format of the protocol you use. |
| 5xx, 529 | Every upstream for the model failed after retries (`overloaded_error`; OpenAI shape 503). | Try again in a few minutes or switch to another model. |

Pay-per-token keys need enough wallet balance to cover a request's estimated maximum cost. Top up (https://quotax.sh/app/billing) if a request is rejected for insufficient balance.
