IN ENGLISH · API DOCS

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:

[01]FIRST CALL

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.
[02]FIRST CALL

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.

POST /v1/chat/completionscurl
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":"سلام"}]}'
The official OpenAI SDK (pip install openai)python
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)
The openai package on npm (npm install openai)javascript
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);
[03]FIRST CALL

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-Toman header says what this request cost in Toman, and X-Request-Id is 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.
[04]FIRST CALL

If it doesn't work

The common answers to a first request
CodeMeansWhat to do
401Means:The key was not acceptedWhat to do:Copy the whole key with no spaces; if it was revoked or expired, make a new one.
402Means:Not enough creditWhat to do:Top up the wallet or pick a model your gift credit pays for.
403Means:A key control refused itWhat to do:Check the key's model list, IP addresses or scope (key controls).
429Means:The rate limit was reachedWhat 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.

[05]FIRST CALL

Next steps

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.