Skip to content
Chanx AI.

Developer documentation

From project key to a visible request.

Implemented gateway behavior, limits and the financial lifecycle. The examples use the real endpoint of this deployment: https://api.chanxai.my.id/v1

Quickstart

  1. Create an account and select a workspace/project.
  2. Check published models and your available Coin. Top up using an active package when available.
  3. Create a project API key. Copy it once and store it in your server's secret configuration.
  4. Send a request to your endpoint with a published model.
# Replace YOUR_API_KEY with the key from the API keys page; never commit it or expose it in a frontend.
curl https://api.chanxai.my.id/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

In PowerShell, use curl.exe and $env:CHANX_API_KEY.

Connect your tools

Chanx AI speaks the OpenAI format and the Anthropic format, so most coding agents and apps work with one key. Pick your tool.

Base URL
https://api.chanxai.my.id/v1

The examples use MODEL_SLUG until a model is published. Pick one from the Models page.

Claude Code

Tested 2026-10-03 with version 2.1.287

Claude Code talks to the Anthropic Messages API. Point it at Chanx AI with environment variables and choose a model with tool support.

  1. Create an API key in the dashboard and pick a model above.
  2. Set the variables below in your terminal. The base URL has no /v1 at the end.
  3. Run claude in your project. Streaming, tool use and file edits work the same way.
macOS / Linux
export ANTHROPIC_BASE_URL="https://api.chanxai.my.id"
export ANTHROPIC_AUTH_TOKEN="sk-chanx-YOUR_KEY"
export ANTHROPIC_MODEL="MODEL_SLUG"
export ANTHROPIC_DEFAULT_OPUS_MODEL="MODEL_SLUG"
export ANTHROPIC_DEFAULT_SONNET_MODEL="MODEL_SLUG"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="MODEL_SLUG"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS="200000"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"
claude
Windows PowerShell
$env:ANTHROPIC_BASE_URL = "https://api.chanxai.my.id"
$env:ANTHROPIC_AUTH_TOKEN = "sk-chanx-YOUR_KEY"
$env:ANTHROPIC_MODEL = "MODEL_SLUG"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "MODEL_SLUG"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "MODEL_SLUG"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "MODEL_SLUG"
$env:CLAUDE_CODE_MAX_CONTEXT_TOKENS = "200000"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"
claude
~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.chanxai.my.id",
    "ANTHROPIC_AUTH_TOKEN": "sk-chanx-YOUR_KEY",
    "ANTHROPIC_MODEL": "MODEL_SLUG",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "MODEL_SLUG",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "MODEL_SLUG",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "MODEL_SLUG",
    "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "200000",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}

Good to know

  • Set all three default model variables, otherwise Claude Code asks for its own Haiku or Sonnet model names for background work.
  • Extended thinking is not forwarded, and Anthropic server tools such as web search are not available. Your own tools and MCP servers work.
  • A coding session sends a large context on every turn, so each request reserves more Coin than a chat message. You are charged the real usage only.
  • To keep it permanent, put the same variables in the env section of ~/.claude/settings.json.

Which endpoint each tool uses

Which endpoint each tool uses
FormatEndpointUsed by
OpenAI Chat CompletionsPOST /v1/chat/completionsOpenCode, Cursor, Cline, Roo Code, Continue, Codex CLI, OpenAI SDKs
OpenAI Responses (text only)POST /v1/responsesSimple scripts that use the Responses API
Anthropic MessagesPOST /v1/messagesClaude Code, Anthropic SDKs
Anthropic token countPOST /v1/messages/count_tokensClaude Code (estimate, no cost)
Model listGET /v1/modelsAny client that lists models

If something does not work

401 invalid or revoked key
Copy the key again from the API keys page. A key is shown once; create a new one if it was lost. Anthropic clients send it as x-api-key, OpenAI clients as a Bearer token; both are accepted.
402 insufficient balance
Top up your Coin. A request reserves funds up front, so a very large context needs a larger balance even though only the real usage is charged.
404 model not found
Use the exact slug from the Models page. The slug is not the provider's own model name.
400 tools are unsupported by this model
Coding agents send tools. Choose a model that lists Tools on the Models page.
429 rate limited
Slow down or raise the limits on the key. Limits apply per key, per account and per address.
Claude Code warns the model is not recognised
Expected for any non-Anthropic model. Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the model's real context window, or CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1.

Authentication

Public /v1 endpoints use Authorization: Bearer sk-chanx-…. The console uses a revocable cookie session; console mutations also require a CSRF token and an allowed Origin.

Restrict keys by project, model, IP/CIDR, expiry, rate and spending limits. Rename, disable, rotate or revoke them from API Keys. Rotation may allow an explicit overlap period. Revocation prevents subsequent authentication.

Provider and 9Router credentials stay on the server. Do not send a console cookie as an API key.

Models

GET /v1/models returns models available to the authenticated key. The public catalog lists published configuration with prices; the console also shows upstream discovery. A discovered ID is not automatically available for inference.

Choose a model that supports the required context, output, tools and vision. The gateway rejects unsupported requests before reserving Coin whenever possible.

Chat Completions

curl https://api.chanxai.my.id/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"YOUR_PUBLISHED_MODEL","messages":[{"role":"user","content":"Hello"}],"max_tokens":128}'

POST /v1/chat/completions accepts the documented Chat subset. Tool and vision support depend on the published model and validated request format. Consult the OpenAPI schema for accepted parameters; unsupported fields are not silently applied.

Responses

curl https://api.chanxai.my.id/v1/responses \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"YOUR_PUBLISHED_MODEL","instructions":"Be concise.","input":"Hello","max_output_tokens":128,"stream":false}'

The implemented subset supports text input, instructions, max_output_tokens and streaming. Tools, multimodal input, previous_response_id, stored conversation state and background mode are not supported. Requests containing unsupported options are rejected before reservation.

Incremental SSE

Set stream to true and use a client that consumes text/event-stream incrementally. Chat streams use data frames and a final [DONE]; Responses streams use typed events such as response.output_text.delta, response.completed and response.failed.

A successful terminal event is emitted only after verified usage and settlement are persisted. A failed or interrupted stream must not be interpreted as completed simply because some text arrived. Missing final usage enters reconciliation; emitted text is not authoritative token accounting.

Disconnects and ambiguous upstream failures may leave a reservation pending reconciliation. Inspect the request ID and billing state instead of repeatedly submitting the same expensive request.

Exact routing and SmartRoute

Use an exact published slug to pin a model. SmartRoute aliases are smart-code, smart-fast, smart-value, smart-document and smart-premium. They require a published routing policy and eligible candidates.

Selections and fallback reasons are stored for inspection. Fallback respects capabilities, key restrictions, budget and price ceilings. The gateway does not silently downgrade a pinned model to bypass a budget.

Spend controls

Workspace, project and API-key policies support daily, monthly and per-request limits, protected balance, warning thresholds and hard limits. Daily/monthly windows use UTC. Exposure includes outstanding reservations so simultaneous requests cannot all spend the same remaining budget.

Redis controls short-lived rates and concurrency. PostgreSQL owns durable budgets and money. Admission fails closed when required abuse controls are unavailable.

Coin, reservations and verified charges

1 Coin = 1,000,000 micro-Coin. Financial API values are integer strings. Do not convert them to JavaScript Number for arithmetic.

  1. Estimate a range from request assumptions; the estimate is not guaranteed.
  2. Reserve a conservative envelope from available balance.
  3. Normalize verified input, output, cache read/write and reasoning usage into non-overlapping classes.
  4. Apply the pinned pricing version, model/reasoning multipliers and margin. Round upward once in micro-Coin.
  5. Settle verified actual cost and release unused reservation atomically.

Missing, malformed or ambiguous usage enters reconciliation. A partial stream is charged only for verified usage. Historical prices do not change when a new version is published.

QRIS top-ups credit only after an administrator verifies the payment. A redirect, screenshot or browser status cannot credit the wallet. Refunds and adjustments require compensating ledger entries; automatic top-up is not supported.

Inspect your ledger

Errors, request IDs and retries

Keep the X-Chanx-Request-Id response header and the request ID in error metadata. Request Explorer shows status, route, verified usage and financial outcome without storing prompt contents by default.

Gateway error handling
StatusAction
400Correct malformed or unsupported request parameters.
401 / 403Check key state, scope and restrictions; do not retry unchanged.
402Check balance, reservation and budget limits.
429Respect Retry-After and reduce rate/concurrency.
5xx / disconnectCheck the request's outcome before retrying; upstream acceptance may be ambiguous.

Do not assume an AI request retry is free or deduplicated. Invoice creation uses an Idempotency-Key; retry the same intended invoice with the same key.