Using SDKs: the OpenAI, Anthropic and Google libraries
No separate library is needed: the official OpenAI, Anthropic and Google GenAI SDKs work once the base URL is changed and a 1xai-* key is set. The base URL is https://1xai.ir/v1 for OpenAI, https://1xai.ir/anthropic for Anthropic and https://1xai.ir/gemini for Google.
Last updated:
The OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://1xai.ir/v1",
api_key="1xai-...",
)
resp = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "Hello"}],
)
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-5.5",
messages: [{ role: "user", content: "Hello" }],
});
console.log(resp.choices[0].message.content);Any other client that takes a custom base URL (Go, .NET, Java, LangChain, LlamaIndex, the Vercel AI SDK and the like) works with the same two settings: the base URL and the key.
export OPENAI_BASE_URL="https://1xai.ir/v1" export OPENAI_API_KEY="1xai-..."
The Anthropic SDK and Claude Code
from anthropic import Anthropic
client = Anthropic(
base_url="https://1xai.ir/anthropic",
api_key="1xai-...",
)
resp = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.content[0].text)export ANTHROPIC_BASE_URL="https://1xai.ir/anthropic" export ANTHROPIC_AUTH_TOKEN="1xai-..." claude
Setting the Anthropic SDK's base URL to https://1xai.ir works too, because /v1/messages reaches the same native route (Anthropic).
The Google GenAI SDK
from google import genai
from google.genai import types
client = genai.Client(
api_key="1xai-...",
http_options=types.HttpOptions(base_url="https://1xai.ir/gemini"),
)
resp = client.models.generate_content(
model="gemini-3.5-flash",
contents="Hello",
)
print(resp.text)The key must travel in a header, not in the URL (authentication). The route is described under Gemini.
The open-source 1xai-sdk package
So that the base URL and the key need not be set by hand each time, the open-source 1xai-sdk package preconfigures the official OpenAI SDK and adds a Toman cost estimate.
npm install 1xai-sdk pip install 1xai-sdk
Ready-made tools
There is a step-by-step guide for Cursor, Claude Code, n8n, Cline, Open WebUI, LibreChat and Continue: tool guides.
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.