SDK Integration
XSI preserves the native semantics of each upstream protocol, so with the official SDKs you only change the base URL and API key. Read the key from an environment variable; never hard-code it.
| SDK / protocol | Base URL | How the key is sent |
|---|---|---|
| OpenAI | https://<API domain>/v1 | Authorization: Bearer |
| Anthropic | https://<API domain> | x-api-key |
| Google GenAI | https://<API domain> | x-goog-api-key |
export XSI_API_KEY="sk-Xvs..."
export XSI_BASE_URL="https://api.xsicontrol.com" # or your own API domainOpenAI SDK
Python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["XSI_API_KEY"],
base_url=os.environ["XSI_BASE_URL"] + "/v1",
)
# Responses
resp = client.responses.create(model="gpt-6.2-sol", input="Explain first-principles thinking")
print(resp.output_text)
# Chat Completions (streaming)
stream = client.chat.completions.create(
model="gpt-6.2-sol",
messages=[{"role": "user", "content": "Write a short poem about routers"}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
# Embeddings
emb = client.embeddings.create(model="text-embedding-3-small", input="XSI")
print(len(emb.data[0].embedding))Node.js / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.XSI_API_KEY,
baseURL: `${process.env.XSI_BASE_URL}/v1`,
});
const resp = await client.responses.create({
model: "gpt-6.2-sol",
input: "Explain first-principles thinking",
});
console.log(resp.output_text);The OpenAI SDK also reads the OPENAI_API_KEY and OPENAI_BASE_URL environment variables, which you can set to your XSI values.
Anthropic SDK
Python
import os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["XSI_API_KEY"],
base_url=os.environ["XSI_BASE_URL"],
)
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain first-principles thinking"}],
)
print(message.content[0].text)Node.js / TypeScript
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: process.env.XSI_API_KEY,
baseURL: process.env.XSI_BASE_URL,
});
const message = await anthropic.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Explain first-principles thinking" }],
});
console.log(message.content[0].text);The Anthropic SDK also reads ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL.
Google GenAI SDK
import os
from google import genai
from google.genai import types
client = genai.Client(
api_key=os.environ["XSI_API_KEY"],
http_options=types.HttpOptions(base_url=os.environ["XSI_BASE_URL"]),
)
resp = client.models.generate_content(model=os.environ["GEMINI_MODEL"], contents="Hello")
print(resp.text)Gemini models must be configured in the price list by the operator. The requested model is the one named in the URL.
Sticky sessions and caching
Give all turns of a conversation a stable session identifier so XSI pins them to the same upstream key, which improves the prompt cache hit rate:
resp = client.responses.create(
model="gpt-6.2-sol",
input="Continue the analysis from the previous turn",
prompt_cache_key="session-7f3a",
)You can also use the session_id or conversation_id request header. See Router API.
Other clients
Any client that lets you set a custom OpenAI or Anthropic endpoint can connect:
- Set the API key to your XSI key (
sk-Xvs...). - Set the base URL to
https://<API domain>/v1(OpenAI format) orhttps://<API domain>(Anthropic format), as the client requires. - Use a model name from the price list.
For Codex and Claude Code, see Codex CLI / App and Claude Code.