Connect LiteLLM to an AI API from Iran
LiteLLM has two uses: a Python library that calls the models of many vendors through one completion function, and a proxy that puts one OpenAI-compatible API in front of them. In both, 1xAi is an OpenAI-compatible provider: the openai/ prefix before the model name, api_base set to https://1xai.ir/v1, and a 1xai-* key.
Setting up LiteLLM
- [01]
Create an account and a 1xAi key. Register at 1xai.ir (the app is in Persian) and confirm your email or mobile number. You spin the sign-up gift wheel (from 100,000 to 1,000,000 Toman of gift credit) once, which is enough to test the connection. Then create a 1xai-* key in the dashboard and copy it at once: a key is shown only once.
- [02]
Install LiteLLM. For the library run pip install -U litellm, and for the proxy pip install -U 'litellm[proxy]'.
- [03]
Call it from code with the openai/ prefix. In litellm.completion write the model name with the openai/ prefix, for example openai/claude-sonnet-5, and pass api_base and api_key. The prefix tells LiteLLM that the target is an OpenAI-compatible API, and the rest of the name is the model's id on 1xAi.
- [04]
Or: a proxy with a config file. In the proxy's configuration file, give each model a row in model_list: model_name is the name your clients call, and litellm_params holds model with the openai/ prefix, api_base, and api_key set to os.environ/ONEXAI_API_KEY.
- [05]
Run the proxy. Run litellm --config litellm_config.yaml --port 4000. Any OpenAI client then reaches the 1xAi models at http://localhost:4000 with the proxy's master_key.
Ready to copy
# pip install -U litellm
# https://docs.litellm.ai/docs/providers/openai_compatible
import os
import litellm
response = litellm.completion(
model="openai/claude-sonnet-5", # openai/ + the 1xAi model id
api_base="https://1xai.ir/v1",
api_key=os.environ["ONEXAI_API_KEY"],
messages=[{"role": "user", "content": "Explain prompt caching in two sentences."}],
)
print(response.choices[0].message.content)
print(response.usage)# https://docs.litellm.ai/docs/proxy/configs
model_list:
- model_name: claude-sonnet
litellm_params:
model: openai/claude-sonnet-5
api_base: https://1xai.ir/v1
api_key: os.environ/ONEXAI_API_KEY
- model_name: gpt-mini
litellm_params:
model: openai/gpt-5-mini
api_base: https://1xai.ir/v1
api_key: os.environ/ONEXAI_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEYpip install -U 'litellm[proxy]'
export ONEXAI_API_KEY="1xai-XXXXXXXXXXXXXXXX"
export LITELLM_MASTER_KEY="sk-change-me"
litellm --config litellm_config.yaml --port 4000
# from another terminal: any OpenAI client, base URL http://localhost:4000
curl http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet", "messages": [{"role": "user", "content": "Hello"}]}'Recommended model
Recommended: claude-sonnet-5. A cheaper alternative: gpt-5-mini. In the proxy, give each need a model_name, for example one for heavy work on the recommended model and one for numerous tasks on the alternative, so that clients change only the name and you change the model behind each name in one file. Every model and its Toman price is on the models page.
What it costs
Each call is billed at the model's Toman price: the vendor's list price plus a markup of 15–30% depending on the model, at the day's dollar rate (refreshed every day at 9 in the morning, Tehran time). LiteLLM's own cost tracking uses its own table of dollar prices, and for names with the openai/ prefix it may show zero or a wrong figure; the real bill, in Toman, is in 1xAi's usage log. Create a separate 1xAi key with a spend cap for each team or app behind the proxy. Usage log (in Persian).
Common errors
- LLM Provider NOT provided
- LiteLLM tells the provider from the model name's prefix. Write openai/claude-sonnet-5, not claude-sonnet-5. The anthropic/ and gemini/ prefixes build a different request; for 1xAi on /v1 use the openai/ prefix.
- Not Found or 404 from LiteLLM
- api_base has to end in /v1, that is https://1xai.ir/v1. Without /v1 the request path is built wrongly.
- 401: invalid key
- The key is wrong, has expired, or you revoked it. Copy it again from the dashboard or create a new one, with no space before or after it.
- 402: insufficient balance
- The account's Toman credit is used up. A wallet top-up by the Zarinpal gateway or the Digipay gateway or card-to-card transfer with a receipt; calls work again as soon as a payment succeeds.
- Model name or routing error
- 1xAi routes by model name: claude-* to Anthropic, gemini-* to Google, deepseek-* to DeepSeek; grok-*, kimi-*, glm-*, qwen*, MiniMax-* and hy* reach the Grok, Kimi, GLM, Qwen, MiniMax and Hunyuan models; every other name goes to OpenAI. Write a model id exactly as the model list shows it.
Every error code is in the error reference.
LiteLLM or the official OpenAI SDK?
If 1xAi is your only provider, the official OpenAI SDK with base_url is enough, because 1xAi itself routes between vendors by model name. LiteLLM helps when you have another provider beside it, or want a proxy with virtual keys for a team.
What does the LiteLLM proxy add to 1xAi?
Virtual keys of your own for the members of a team, a budget and limits for each (with a Postgres database), fallbacks between models, and logs on your own server. Behind it is the same 1xAi: one 1xai-* key, the models of 10 vendors, and a Toman bill.
Other guides: Cursor, Claude Code, Codex CLI, n8n, Dify, Cline, Open WebUI, LibreChat, Continue, LangChain, LlamaIndex, Vercel AI SDK.
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.