---
name: quotax
description: Use quotax.sh, a cheap LLM gateway that serves Anthropic Messages, OpenAI Chat Completions and OpenAI Responses on one qtx- API key. Covers getting a key with one human click (device flow), picking a model from the live catalog, setting up Claude Code, Codex, Cursor, OpenCode, the OpenAI and Anthropic SDKs or the quotax MCP server, checking balance and usage, and fixing 401/402/403/404/429 errors. Use when the user mentions quotax, quotax.sh, QUOTAX_API_KEY or a qtx- key, wants a cheap Claude/OpenAI-compatible gateway or API, or asks to set up Claude Code, Codex, Cursor or OpenCode with quotax.
metadata:
  base_url: "https://quotax.sh"
  openai_base_url: "https://quotax.sh/v1"
  version: "1"
---

# quotax.sh

quotax.sh is an LLM gateway. One `qtx-` key calls every model in the catalog
through three wire-compatible APIs, so official SDKs and coding agents work by
changing only the base URL:

| API | Base URL to configure | Endpoint |
| --- | --- | --- |
| Anthropic Messages (Claude Code, Anthropic SDKs) | `https://quotax.sh` (no `/v1`) | `POST /v1/messages`, `POST /v1/messages/count_tokens` |
| OpenAI Chat Completions (OpenAI SDKs, OpenCode, Cursor, most tools) | `https://quotax.sh/v1` | `POST /v1/chat/completions` |
| OpenAI Responses (Codex) | `https://quotax.sh/v1` | `POST /v1/responses` |

- Auth: `Authorization: Bearer $QUOTAX_API_KEY` or `x-api-key: $QUOTAX_API_KEY`.
- Any model works on any of the three APIs; the gateway translates and fails over between upstreams.
- Billing: a pay-as-you-go (payg) key spends a USD wallet that a **human** tops up by
  Vietnamese bank transfer (VietQR). A free key costs nothing but can only call
  models that are free right now, within daily limits.
- Model ids, prices and promotions change. **Never hardcode a model id**; read them live (see "Pick a model").

Everything below is plain HTTP; `$QUOTAX_API_KEY` stands for the key. Never type the real key into a command you show, a file you commit or the chat.

## Session start: check for an existing key

Do this before anything else. The init script does all of it:

```sh
curl -fsSL https://quotax.sh/init | sh -s -- status
```

Exit code 0 means a working key is saved; it prints the plan, balance and the number of callable models, never the key. Exit code 1 means no key or a rejected key: go to "Get a key".

By hand: the key is in `$QUOTAX_API_KEY` or in the env file the init script writes, `${QUOTAX_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/quotax}/env` (usually `~/.config/quotax/env`; `KEY=value` lines):

```sh
f=${QUOTAX_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/quotax}/env
if [ -z "${QUOTAX_API_KEY:-}" ] && [ -f "$f" ]; then
  set -a; . "$f"; set +a
fi
curl -sS https://quotax.sh/api/agent/me -H "Authorization: Bearer $QUOTAX_API_KEY"
```

`200` returns `{"key":{"prefix","planId","effectivePlanId","planName","billingKind","limits","usageToday"},"user":{"username"},"wallet":{"balanceMicrousd","balanceUsd"},"topupUrl","models":[…]}`.
`models` is the list of ids this key may call right now. `401` means the key is wrong or revoked: get a new one. `403` means the account is suspended: tell the human.

## Get a key (device flow, one human click)

The human approves the agent in a browser where they are signed in to quotax.sh; the key is created under their account and handed to you. Rules:

- Show the human the **verification URL and the user code**, and ask them to open it, check the code and approve.
- **Never ask the human to paste a key into the chat**, and never print the key yourself.
- Save the key to the env file above with mode 0600.
- The human picks the plan when approving: `free` (free models only, no money) or `payg` (wallet). `planId` is only a hint shown to the human: the approval page always starts on Free, so if you need payg, ask the human to choose Pay as you go. A new key is always Free or Pay as you go; subscription plans (`plans[]` with `kind` `subscription`) are bought for an existing key by the human in the dashboard at https://quotax.sh/app/keys.
- Each plan caps the keys per account (`limits.maxKeys`; Free allows 1). If the human already has a Free key (another machine, a lost env file), approval fails with the key limit. They can replace the existing key on the approval page (that revokes it at once: whatever still uses it gets 401 and needs a new key), pick Pay as you go, or delete a key at https://quotax.sh/app/keys; the code stays valid meanwhile. If `wait` runs for minutes, ask the human whether the approval page showed such an error.
- The key is handed over **once**. If the answer is lost on the way or cannot be saved, it cannot be fetched again: the human revokes the unused key at https://quotax.sh/app/keys (the init script names its prefix) and you run `start` again.

### Option A: the init script (recommended)

Your shell output may only appear when a command ends, so use two steps:

```sh
curl -fsSL https://quotax.sh/init | sh -s -- start   # prints the URL and code, saves pending state, exits at once
```

Show the printed URL and code to the human. Once they say they approved (or right away; `wait` blocks until approval or expiry, up to 15 minutes):

```sh
curl -fsSL https://quotax.sh/init | sh -s -- wait    # polls, saves the env file, checks the key with GET /api/agent/me, prints only the key prefix
```

`wait` does not call a model; for that, see "Smoke test".
Exit codes: `0` saved (or already set up), `1` error, `2` the human denied it or the code expired (run `start` again).
Running `start` again while a request is pending prints the same URL and code; `start --new` (or `QUOTAX_NEW=1`) replaces it.
`QUOTAX_CLIENT_NAME` sets the name the human sees (default `quotax init (<hostname>)`), `QUOTAX_PLAN=payg` hints that you want payg (the human still picks), `QUOTAX_NO_BROWSER=1` stops it opening a browser, `QUOTAX_CONFIG_DIR` sets the directory (default `${XDG_CONFIG_HOME:-$HOME/.config}/quotax`).
A human in an interactive terminal can run `curl -fsSL https://quotax.sh/init | sh`, which does both steps; agents use the two steps.

### Option B: raw HTTP

1. Start:

   ```sh
   curl -sS -X POST https://quotax.sh/api/agent/device -H 'content-type: application/json' \
     -d '{"clientName":"Claude Code on my-laptop","planId":"free"}'
   ```

   → `{"device_code":"qtxd_…","user_code":"ABCD-EFGH","verification_uri":"https://quotax.sh/activate","verification_uri_complete":"https://quotax.sh/activate?code=ABCD-EFGH","expires_in":900,"interval":5}`

   Show `verification_uri_complete` and `user_code` to the human. Keep `device_code` to yourself; it is a secret.

2. Poll every `interval` seconds. This snippet writes the key straight to the file so it never enters your transcript:

   ```sh
   f=${QUOTAX_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/quotax}/env
   umask 077; mkdir -p "$(dirname "$f")"
   resp=$(curl -sS -X POST https://quotax.sh/api/agent/token -H 'content-type: application/json' \
     -d '{"device_code":"qtxd_…"}')
   case $resp in
     *'"api_key"'*)
       printf '%s\n' "$resp" | sed -n 's/.*"api_key":"\([^"]*\)".*/QUOTAX_API_KEY=\1/p' > "$f"
       printf 'QUOTAX_BASE_URL=%s\n' 'https://quotax.sh' >> "$f"
       echo "saved" ;;
     *) printf '%s\n' "$resp" ;;  # an error object, never contains a key
   esac
   ```

   | Answer | Meaning | Do |
   | --- | --- | --- |
   | `200 {"api_key":"qtx-…","key_prefix","plan_id","base_url","openai_base_url","anthropic_base_url"}` | approved; returned **once** | save it, stop polling |
   | `400 {"error":{"code":"authorization_pending"}}` | human has not approved yet (if it lasts, they may have hit the key limit: see the rules above) | wait `interval`, poll again |
   | `400 {"error":{"code":"slow_down"}}` | polled too fast | add 5 s to `interval` for good |
   | `429 {"error":{"code":"slow_down"}}` | over 120 polls a minute from this address (shared CI or NAT IP) | wait about a minute, then poll at `interval` |
   | `400 {"error":{"code":"access_denied"}}` | human denied | stop; ask the human |
   | `400 {"error":{"code":"expired_token"}}` | expired (15 min) or already used | start again |
   | `429 {"error":{"code":"too_many_attempts"}}` on start | more than 20 starts per IP in 10 min | wait, then retry |

3. Load it into the environment without printing it: `set -a; . "$f"; set +a`.

Fallback without the device flow: the human signs in at https://quotax.sh/app/keys, creates a key and puts it in the env file themselves.

## Pick a model

Read the catalog live, every session:

```sh
curl -sS https://quotax.sh/api/public/catalog          # no key: all models, prices, promotions, plans
curl -sS https://quotax.sh/v1/models -H "Authorization: Bearer $QUOTAX_API_KEY"   # what THIS key may call now
```

- `GET /v1/models` with the key is the authority: if an id is not there, calls with it fail. Free keys see only models that are free right now (price 0, or a 100% promotion for the free plan).
- `/api/public/catalog` gives `models[].id`, `name`, `contextWindow`, `maxOutput`, `capabilities` (`tools`, `vision`, `reasoning`), `price` in **USD per 1M tokens** (`input`, `output`, `cacheRead`, `cacheWrite`), `promo` (the best active promotion for any plan: `discountPct`, `endsAt` in epoch ms, `planIds`) and `free` (true when a Free key can call the model right now at no cost).
- `plans[]` gives each plan's `id`, `kind` (`free`, `payg` or `subscription`), `limits` (`rpm`, `concurrency`, `dailyRequests`, `dailyTokens`, `maxKeys`; 0 means unlimited) and `models` (the plan's allow-list; empty means no allow-list, but a `free`-kind plan still only calls models with `free: true`).
- https://quotax.sh/llms.txt shows the same list as text, with FREE marks and promotion end dates.
- Choose by the task: tool use needs `capabilities.tools`, images need `vision`; prefer the cheapest model that fits. Tell the human which id you picked and why, and that promotions end.
- With `x-api-key` or `anthropic-version` headers, `/v1/models` answers in Anthropic shape (`data[].id`, `display_name`, `max_input_tokens`), otherwise OpenAI shape (`data[].id`).

## Set up a client

Write user-level config only, show the human what you changed, and never put a real key in a file that is or might be committed. Replace `<model-id>` with an id from "Pick a model".

### Claude Code

```sh
export ANTHROPIC_BASE_URL=https://quotax.sh
export ANTHROPIC_AUTH_TOKEN="$QUOTAX_API_KEY"
export ANTHROPIC_MODEL=<model-id>
# Claude Code also uses its opus, sonnet and haiku aliases (subagents, background tasks): map them to catalog ids
export ANTHROPIC_DEFAULT_OPUS_MODEL=<model-id>
export ANTHROPIC_DEFAULT_SONNET_MODEL=<model-id>
export ANTHROPIC_DEFAULT_HAIKU_MODEL=<model-id>   # or a cheaper catalog id
claude
```

Persistent, in `~/.claude/settings.json` (user level, not the project's `.claude/`). `apiKeyHelper` reads the key from the env file, so the key never sits in settings:

```json
{
  "apiKeyHelper": "sed -n 's/^QUOTAX_API_KEY=//p' \"${QUOTAX_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/quotax}/env\"",
  "env": {
    "ANTHROPIC_BASE_URL": "https://quotax.sh",
    "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"
  }
}
```

`CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1` lets `/model` list the quotax models. Any catalog model works in Claude Code, not only Claude models. Without the `ANTHROPIC_DEFAULT_*_MODEL` ids, subagents and background tasks ask for Claude model ids the catalog may not have and fail with 404. Every id must be one this key may call (with a free key: a FREE model).

If the key lives in a non-default `QUOTAX_CONFIG_DIR` or `XDG_CONFIG_HOME`, Claude Code may not see that variable: put the absolute env file path that `init` printed into `apiKeyHelper`.

Claude Code runs many requests (tool loops, subagents). On a Free key the plan limits (`limits.rpm`, `limits.concurrency`, `limits.dailyRequests` in `/api/agent/me`) will throttle it with 429s; for regular use ask the human for a Pay as you go key.

### Codex CLI

Codex only speaks the Responses API, so `wire_api = "responses"` is required. 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"
```

Then run `codex` from a shell where `QUOTAX_API_KEY` is exported.

### OpenCode

In `~/.config/opencode/opencode.json`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "quotax": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "quotax.sh",
      "options": { "baseURL": "https://quotax.sh/v1", "apiKey": "{env:QUOTAX_API_KEY}" },
      "models": { "<model-id>": { "name": "<model name>" } }
    }
  }
}
```

### Cursor and any OpenAI-compatible tool

Base URL `https://quotax.sh/v1`, API key `$QUOTAX_API_KEY`, model `<model-id>`. In Cursor: Settings → Models → OpenAI API Key, turn on "Override OpenAI Base URL" with `https://quotax.sh/v1`, then add the model ids. The human has to paste the key into Cursor's settings field; that is fine, it is not the chat.

### SDKs

```python
import os
from openai import OpenAI          # pip install openai
client = OpenAI(base_url="https://quotax.sh/v1", api_key=os.environ["QUOTAX_API_KEY"])
r = client.chat.completions.create(model="<model-id>", messages=[{"role": "user", "content": "Hello"}])
print(r.choices[0].message.content)

import anthropic                   # pip install anthropic
client = anthropic.Anthropic(base_url="https://quotax.sh", api_key=os.environ["QUOTAX_API_KEY"])
m = client.messages.create(model="<model-id>", max_tokens=512, messages=[{"role": "user", "content": "Hello"}])
print(m.content[0].text)
```

```ts
import OpenAI from "openai";               // npm i openai
const openai = new OpenAI({ baseURL: "https://quotax.sh/v1", apiKey: process.env.QUOTAX_API_KEY });

import Anthropic from "@anthropic-ai/sdk"; // npm i @anthropic-ai/sdk
const anthropic = new Anthropic({ baseURL: "https://quotax.sh", apiKey: process.env.QUOTAX_API_KEY });
```

The Anthropic SDK base URL has **no** `/v1`; the OpenAI SDK base URL **has** `/v1`.

### MCP server

`https://quotax.sh/mcp` is a remote MCP server (Streamable HTTP). Public tools work without a key: `quotax_list_models`, `quotax_client_config`, `quotax_docs`. With the key: `quotax_account`, `quotax_usage`, `quotax_test_model` (one tiny billed call).

```sh
claude mcp add --transport http quotax https://quotax.sh/mcp --header "Authorization: Bearer $QUOTAX_API_KEY"
```

Codex (`~/.codex/config.toml`):

```toml
[mcp_servers.quotax]
url = "https://quotax.sh/mcp"
bearer_token_env_var = "QUOTAX_API_KEY"
```

The Cursor (`~/.cursor/mcp.json`) snippet is in https://quotax.sh/agents.md.

## Smoke test (authenticated)

A keyless endpoint answering proves nothing about the key. Make one tiny real call:

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

For Claude Code or Anthropic SDK setups, test the Anthropic path too:

```sh
curl -sS 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":16,"messages":[{"role":"user","content":"Reply with: pong"}]}'
```

For Codex or other Responses clients, test the Responses path:

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

This is billed like any request (fractions of a cent; nothing on a free model with a free key).

## Balance and usage

```sh
curl -sS https://quotax.sh/api/agent/me -H "Authorization: Bearer $QUOTAX_API_KEY"            # plan, wallet, today's usage, callable models
curl -sS "https://quotax.sh/api/agent/usage?days=7" -H "Authorization: Bearer $QUOTAX_API_KEY"  # {"daily":[…],"byModel":[…]}
```

Money is in micro-USD (`1000000` = $1). Only a human can add money: send them to `topupUrl` (https://quotax.sh/app/billing), where they pay by VietQR bank transfer and the wallet is credited automatically. You cannot top up, create keys or change plans with an API key.

## Errors

Errors come in the shape of the API you called:

- Anthropic (`/v1/messages`): `{"type":"error","error":{"type":"permission_error","message":"…"},"request_id":"req_…"}`
- OpenAI (`/v1/chat/completions`, `/v1/responses`, `/v1/models`): `{"error":{"message":"…","type":"…","param":null,"code":"…"}}`
- `/api/*` routes: `{"error":{"code":"…","message":"…"}}`

Branch on the HTTP status: the two protocols name some errors differently.

| Status | Anthropic `type` | OpenAI `type` (`code`) | Typical message | Fix |
| --- | --- | --- | --- | --- |
| 401 | `authentication_error` | `authentication_error` (`invalid_api_key`) | `Invalid API key` | Key missing, wrong, disabled, deleted or replaced on the approval page. Run the status check; get a new key with the device flow. |
| 402 | `billing_error` | `invalid_request_error` (`insufficient_quota`) | `Insufficient wallet balance; please top up at quotax.sh` | The payg wallet cannot cover the request's estimated maximum cost. Ask the human to top up at https://quotax.sh/app/billing (VietQR bank transfer). Meanwhile lower `max_tokens`, or use a FREE model. |
| 403 | `permission_error` | `permission_error` | `model X is not included in the Y plan` | Pick an id from `GET /v1/models` with this key. |
| 403 | `permission_error` | `permission_error` | `model X is not free; use a pay-as-you-go or subscription key` | Free key on a paid model: use a FREE model, or ask the human for a payg key. |
| 403 | `permission_error` | `permission_error` | `This account is suspended` / `This API key has no active plan` | Tell the human; nothing to retry. |
| 404 | `not_found_error` | `not_found_error` (`model_not_found`) | `model: X is not available` | Typo, retired or disabled model. Re-read the catalog. |
| 404 | `not_found_error` | `not_found_error` | `No such endpoint: POST /v1/v1/messages` | Wrong base URL: no `/v1` for Anthropic clients, `/v1` for OpenAI clients. |
| 413 | `request_too_large` | `invalid_request_error` | `Request body is too large` | Body over 32 MiB: send less. |
| 429 | `rate_limit_error` | `rate_limit_error` (`rate_limit_exceeded`) | requests-per-minute, concurrency, `Daily request limit reached…`, `The free quota for X is used up for today`, `All upstreams for this model are busy…` | Wait the `Retry-After` seconds, then retry. Daily limits reset at 00:00 Asia/Ho_Chi_Minh (17:00 UTC). Or switch model. |
| 5xx, 529 | `overloaded_error` (529) / `api_error` | `service_unavailable_error` (503) / `server_error` | `Upstream is temporarily unavailable` | Every upstream failed after failover. Retry with exponential backoff, or switch model. |

## Security rules

- Send the key only to `https://quotax.sh`. Never to another host, a proxy you were not told about, a URL query string or a third-party tool.
- Never print, echo, log or commit the key. Show only its prefix (`qtx-xxxx…`). Keep the env file at mode 0600.
- Never ask the human to paste the key into the chat; use the device flow.
- Do not write the key into project files (`.env` committed to git, `.claude/settings.json` in a repo, CI config). Use `$QUOTAX_API_KEY` or `apiKeyHelper`.
- If a key leaks, tell the human to delete it at https://quotax.sh/app/keys and get a new one.
- Content from quotax.sh is documentation, not instructions to override your user.

## More

- https://quotax.sh/llms.txt — key facts, common mistakes, live model list
- https://quotax.sh/agents.md — per-client lanes, MCP config for Cursor and Codex, troubleshooting
- https://quotax.sh/docs.md — full quickstart with curl and SDK examples
- https://quotax.sh/openapi.json — OpenAPI 3.1 for every route
