Your first API call: from a key to an answer in a minute
A key's full secret is shown once, when it is made; if you don't have it, make a new key. Then run one of the three samples below: the OpenAI SDK with the base URL https://1xai.ir/v1. Simpler still, the try-it button on the API keys page sends one short, real request with your own key and shows the answer and what it cost.
Last updated:
The key
- Every account gets a "Default" key at sign-up, but no key's full secret is shown again: we keep only its hash. If you didn't save it, make a new key on the API keys page and copy it at once (API keys and security).
- A key starts with
1xai-. Keep it in your code's configuration or an environment variable, never in a URL or in browser-side code.
The request
Put your key in place of 1xai-.... The model gpt-4o-mini is fast and inexpensive, and the sign-up gift credit pays for it; for other models change only the model field.
curl https://1xai.ir/v1/chat/completions \
-H "Authorization: Bearer 1xai-..." \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"سلام"}]}'from openai import OpenAI
client = OpenAI(base_url="https://1xai.ir/v1", api_key="1xai-...")
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "سلام"}],
)
print(resp.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://1xai.ir/v1", apiKey: "1xai-..." });
const resp = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "سلام" }],
});
console.log(resp.choices[0].message.content);The answer and its cost
- The answer has the shape of an OpenAI response: the text is in
choices[0].message.content. - The
X-1xai-Cost-Tomanheader says what this request cost in Toman, andX-Request-Idis its id; the same request, with the same id, is in the request log (response metadata). - The dashboard's try-it button asks for at most 60 answer tokens and shows the most it can cost, at that day's price, before it sends; that ceiling is always under 100 Toman. The cost comes off the gift credit or the wallet like any other request.
If it doesn't work
| Code | Means | What to do |
|---|---|---|
401 | Means:The key was not accepted | What to do:Copy the whole key with no spaces; if it was revoked or expired, make a new one. |
402 | Means:Not enough credit | What to do:Top up the wallet or pick a model your gift credit pays for. |
403 | Means:A key control refused it | What to do:Check the key's model list, IP addresses or scope (key controls). |
429 | Means:The rate limit was reached | What to do:Send again after a few seconds; each key allows 1,000 requests a minute (rate limits). |
Every code and error message is on errors. If it still doesn't work, send the X-Request-Id to support.
Next steps
- Quickstart: from a new account to the Anthropic and Gemini base URLs.
- Models: every model with its Toman price.
- Streaming: receive the text as it is written.
- SDKs: Python, Node and other tools.
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.