IN ENGLISH · API DOCS

MCP server: your 1xAi key in Claude Code and Cursor

1xAi's own MCP server is one URL that any MCP client (such as Claude Code or Cursor) connects to with your API key. The model inside that client gets five tools: the models and their prices, the estimated cost of a request, your balance, your usage, and a chat with any model. A chat is an ordinary POST /v1/chat/completions call: the same price, the same usage record and the same request id. The key's scope, model list, address list, rate limit and spend cap all apply.

Last updated:

[01]MCP SERVER

The endpoint and the protocol

The server is at https://1xai.ir/v1/mcp (or https://api.1xai.ir/v1/mcp, which reaches the same service). It is remote MCP over Streamable HTTP: one URL that takes POST only, each JSON-RPC message its own request, and each answer one JSON object. The server keeps no session, opens no event stream and sends nothing on its own; GET and DELETE answer 405. Protocol versions: 2026-07-28 (no handshake), and 2025-11-25 and 2025-06-18 (with initialize).

  • Authentication is the Authorization: Bearer 1xai-... header, as on every /v1 path (authentication). Sign-in with OAuth is not supported.
  • A request from a web page (one with an Origin header) is refused with 403, and the server sends no CORS header. Keep the key in the client's settings, never in a web page.
  • No tool fetches a URL, a file or any outside resource: the read tools read the account API itself, and chat is the gateway's own chat route.
[02]MCP SERVER

Adding it to a client

Claude Code

bashbash
claude mcp add --transport http 1xai https://1xai.ir/v1/mcp \
  --header "Authorization: Bearer 1xai-..."

# for every project
claude mcp add --transport http 1xai --scope user https://1xai.ir/v1/mcp \
  --header "Authorization: Bearer 1xai-..."

In a project's .mcp.json, which lives in the repository, do not write the key: put it in an environment variable of your own name. Claude Code leaves its own credential variables (such as ANTHROPIC_API_KEY) empty in a remote server's headers.

.mcp.jsonjson
{
  "mcpServers": {
    "1xai": {
      "type": "http",
      "url": "https://1xai.ir/v1/mcp",
      "headers": {
        "Authorization": "Bearer ${ONEXAI_API_KEY}"
      }
    }
  }
}

Cursor

`~/.cursor/mcp.json`, or `.cursor/mcp.json` in a projectjson
{
  "mcpServers": {
    "1xai": {
      "url": "https://1xai.ir/v1/mcp",
      "headers": {
        "Authorization": "Bearer ${env:ONEXAI_API_KEY}"
      }
    }
  }
}

Claude Desktop

Claude Desktop's connectors attach a remote server through an OAuth sign-in and take no key. Use the open-source mcp-remote bridge instead: it runs on your own computer (it needs Node.js) and sends the key in the header. The snippet names one exact release of it, so npx never fetches a newer one unasked. Restart Claude Desktop after saving the file.

claude_desktop_config.jsonjson
{
  "mcpServers": {
    "1xai": {
      "command": "npx",
      "args": ["-y", "mcp-remote@0.16.7", "https://1xai.ir/v1/mcp", "--transport", "http-only", "--header", "Authorization:${ONEXAI_AUTH}"],
      "env": { "ONEXAI_AUTH": "Bearer 1xai-..." }
    }
  }
}

Other clients

Any client that speaks remote MCP over Streamable HTTP and can send a header works: the URL https://1xai.ir/v1/mcp and the Authorization header. A client that knows only an OAuth sign-in cannot connect.

[03]MCP SERVER

The tools

The MCP server's tools
ToolWhat it doesKey scope
list_modelsWhat it does:The models this key can call, with each one's vendor, kind and list price in Toman per thousand input and output tokens. Filters: vendor, kind and search; at most 200 rows.Key scope:inference, usage and full
estimate_costWhat it does:The cost of a request in Toman before it is sent, from the model and the token counts, at your own account's rates. Nothing is charged.Key scope:inference, usage and full
get_balanceWhat it does:The spendable balance, the wallet and the gift credit. A company workspace key sees the spendable balance only.Key scope:usage and full
get_usageWhat it does:Calls, tokens and Toman by day and by model; the same records as GET /v1/usage/summary (account API). days (default 7), or from and to; at most 90 days.Key scope:usage and full
chatWhat it does:One chat completion: model, messages (plain text, at most 64) and max_tokens (default 1,024, at most 16,384).Key scope:inference and full

The tool list (tools/list) shows only the tools of the key's scope. A tool outside it gets a tool error with code key_scope_denied (scopes). An inference key sees the models and prices (what GET /v1/models already gives it), never the account's balance or usage. For a client that should only read, make a usage key: even if it leaks, it cannot spend.

[04]MCP SERVER

What it costs

  • The four read tools cost nothing.
  • chat is an ordinary API call: the same price, the same order of payment (plan credit, gift credit, then the wallet) and the same hold and refund as POST /v1/chat/completions (billing).
  • Its usage record is in your logs. The request_id of the tool's answer and the X-Request-Id header of the HTTP answer are that record's id (response metadata), and cost_toman is what it was billed.
  • estimate_cost gives the list price at your account's own markup; plan credit or gift credit may pay part of it.
  • Every MCP request is one request of the key's rate limit (rate limits).
[05]MCP SERVER

Key controls

  • The model list: list_models shows only the models on it, and estimate_cost and chat refuse the others with code key_model_not_allowed (model list).
  • The address list: a request from another address answers 403 with code key_ip_not_allowed, as on every /v1 path (address list).
  • The key's spend cap: chat counts toward it, and a key at its cap answers 401 with code key_capped.
  • Give MCP a key of its own, with a spend cap if the client chats (keys).
[06]MCP SERVER

Limits

The MCP server's limits
WhatLimit
A request bodyLimit:1 MB; more answers 413
The messages of chatLimit:64 plain-text messages
max_tokens of chatLimit:default 1,024, at most 16,384
The window of get_usageLimit:at most 90 days
The rows of list_modelsLimit:at most 200
The read tools, per keyLimit:list_models 60 a minute, estimate_cost 120 a minute, get_balance 60 a minute and get_usage 20 a minute

A read tool past its own per-minute limit gets a tool error with code rate_limited; try again a minute later. chat has no separate limit: the key's own rate limit applies.

[07]MCP SERVER

Errors

The MCP server's error answers
AnswerWhen
A tool result with isError: trueWhen:The tool hit a rule, or the gateway refused the call. structuredContent.error has the code (the codes of /v1: error reference) and the message, and for chat the request id and the gateway's HTTP status.
401When:No key, or an unknown, revoked, expired or capped one.
403When:An address off the list, the key's scope, or a request from a web page.
405When:GET, DELETE or any method but POST.
413When:A body over the limit.
415When:A Content-Type other than application/json.
A JSON-RPC errorWhen:A malformed request (-32700 and -32600, a batch of messages included), an unknown method (-32601), bad params or an unknown tool (-32602), headers that do not match the body (-32020), or an unsupported version (-32022).

1xAi is an independent gateway. It is not affiliated with, endorsed by, or a reseller for OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Z.ai, Alibaba Qwen, MiniMax or Tencent Hunyuan. Requests are relayed upstream rather than answered by models of our own, so each provider's own usage policies apply to what their models will and will not do, and their model availability is theirs to change. Current reachability is published on the status page.