X420.aiDocs

API Reference

One endpoint. Full OpenAI compatibility.

Base URL

https://api.x420.ai/v1

Authentication

Pass your API key as a Bearer token in the Authorization header:

Authorization: Bearer sk-proxy-your-key

POST /v1/chat/completions

POST/v1/chat/completions

Forwards your request to the best available upstream model and bills the actual token usage from your wallet.

Request body

ParameterTypeDescription
modelstringRequired. The model ID, e.g. openai/gpt-4o or anthropic/claude-sonnet-4-6.
messagesarrayRequired. Array of message objects with role and content.
streambooleanOptional. Set to true to receive a Server-Sent Events stream.
max_tokensintegerOptional. Hard cap on completion tokens. Defaults to 4096, max 16384.
Any additional parameter supported by the target model (temperature, top_p, system, etc.) is passed through to the upstream API unchanged.

Response

The response body is passed through verbatim from the upstream model. Two extra headers are added:

HeaderDescription
x-balance-centsYour wallet balance after this request (integer, cents).
x-cost-centsHow much this request cost (integer, cents).
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "openai/gpt-4o-mini",
  "choices": [{
    "message": { "role": "assistant", "content": "Hello!" },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 4,
    "total_tokens": 16
  }
}

Streaming

When stream: true, the response is a standard SSE stream. The final chunk includes the usage stats needed for billing. You don't need to do anything special — X420.ai handles billing automatically.

// Node.js streaming example
const stream = await client.chat.completions.create({
  model: 'openai/gpt-4o-mini',
  messages: [{ role: 'user', content: 'Tell me a story.' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}

Error codes

HTTPCodeDescription
400VALIDATION_ERRORRequest body failed schema validation.
400MODEL_UNKNOWNThe requested model ID is not available on OpenRouter.
401MISSING_API_KEYNo Bearer token in the Authorization header.
401INVALID_API_KEYThe key does not match any active account.
402INSUFFICIENT_BALANCEYour wallet balance is lower than the estimated request cost.
403ACCOUNT_SUSPENDEDYour account has been suspended. Contact support.
429Rate limit exceeded (300 req/min per key).
502UPSTREAM_ERROROpenRouter returned an error after 3 retries.