Thin, drop-in Python SDK for the 1xAi gateway (https://1xai.ir) — OpenAI, Claude, Gemini and DeepSeek from inside Iran, billed in Toman.
Project description
onexai — Python SDK for the 1xAi gateway
1xAi is an OpenAI-compatible AI gateway for Iran: one key and one base URL for OpenAI, Anthropic Claude, Google Gemini and DeepSeek — no VPN, no foreign card, billed in Toman.
pip install 1xai-sdk
from onexai import OneXAI, cost_of_response
client = OneXAI() # reads ONEXAI_API_KEY, falls back to OPENAI_API_KEY
reply = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "سلام! یک جوک فارسی بگو"}],
)
print(reply.choices[0].message.content)
print(cost_of_response(reply)) # -> 102 Toman (gpt-4o-mini, 14in/23out)
Why this package is thin (and why that is the point)
1xAi's whole claim is that it is the OpenAI API at a different base URL. So this
package does not re-implement an SDK — it depends on the official openai package and
pre-configures it. Writing our own HTTP, streaming, retry and tool-call layer would
mean shipping a worse copy of a client OpenAI already maintains, and it would drift
every time the API gains a field.
You do not strictly need this package at all:
from openai import OpenAI
client = OpenAI(api_key="1xai-...", base_url="https://1xai.ir/v1")
That is the entire integration. What onexai adds is the small set of things the
generic SDK cannot know about a gateway in Iran:
| Toman cost | estimate_cost() / cost_of_response() priced from 1xAi's public catalogue |
| Real errors | the gateway answers in Persian; explain() turns that into one actionable English sentence — including 402, which on this gateway means your wallet is empty, not your code is broken |
| Key validation | pasting an sk-... key fails loudly at construction instead of as a confusing 401 later |
| Native passthroughs | anthropic_client() and gemini_client() for prompt caching, thinking budgets and cachedContents |
onexai doctor |
one command that tells you which of key / network / credit / upstream is actually broken |
CLI
onexai doctor # diagnose key, connectivity, credit, upstream health
onexai price gpt-4o-mini 1000 500 # Toman cost of a call
onexai models --provider anthropic # what you can call, with prices
onexai status # live upstream health, as seen from Iran
Cost estimation
Prices come from https://1xai.ir/api/models — public, no key required. A snapshot
ships with the package so the helper works offline; pass live=True to fetch current
prices.
from onexai import estimate_cost
e = estimate_cost("claude-opus-4-5", input_tokens=50_000, output_tokens=2_000)
print(e.total_toman) # 66,067.0
print(e.provider) # anthropic
Audio and image endpoints are billed per second and per image, so they are not in
the token catalogue. estimate_cost("whisper-1", ...) raises UnknownModelError
explaining that, rather than quietly returning zero.
Native passthroughs
The OpenAI-compatible path silently drops provider-specific features. When you need them, use the native endpoints:
from onexai import anthropic_client # pip install '1xai-sdk[anthropic]
claude = anthropic_client() # -> https://1xai.ir/anthropic
msg = claude.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
system=[{"type": "text", "text": BIG_DOC,
"cache_control": {"type": "ephemeral"}}], # dropped on /v1
messages=[{"role": "user", "content": "خلاصه کن"}],
)
print(msg.usage.cache_read_input_tokens)
Full cookbook
Runnable recipes for Cursor, Continue, Cline, Open WebUI, n8n, streaming, Persian Whisper transcription, image generation and cost control live in the repository README.
License
MIT. Not an official 1xAi product unless the 1xAi team adopts it; see the repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file 1xai_sdk-0.1.0.tar.gz.
File metadata
- Download URL: 1xai_sdk-0.1.0.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec223d37fadf95c0b6ef801aecb2f83386951589ca5a74a7fc73a6f30414c60
|
|
| MD5 |
5583cb4207ef43035551d3f8cfc18d07
|
|
| BLAKE2b-256 |
a8dc2d7e235c03274e49585b012f82417825966455399c5bf85dfb6fb94bf037
|
File details
Details for the file 1xai_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: 1xai_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fa351a0c1ee00de9c527c9308a95de01701a4be3dcf0d5f8c1dbea0ba4d19bc
|
|
| MD5 |
e2597e039f7b7b381cdf494ca7cef5b4
|
|
| BLAKE2b-256 |
f04cc7242bd6d2369ca54c12a6a82bff36f01d86e54c46ee5f899664fa6d112e
|