Integrations
Development SDKs
Point the SDK's Base URL to KHaiXAPI to use OpenAI, Anthropic, Vercel AI SDK, or LangChain. Confirm the protocol used by the SDK, then run the minimal text examples below.
Choose an SDK and protocol
| SDK | Example protocol | Base URL |
|---|---|---|
| OpenAI Python | Responses | https://api.khaix.net/v1 |
| OpenAI JavaScript | Responses | https://api.khaix.net/v1 |
| Anthropic Python | Anthropic Messages | https://api.khaix.net |
| Anthropic TypeScript | Anthropic Messages | https://api.khaix.net |
| Vercel AI SDK | Explicitly select Responses or Chat Completions | https://api.khaix.net/v1 |
LangChain ChatOpenAI | Chat Completions | https://api.khaix.net/v1 |
The examples read the key from the KHAIX_API_KEY environment variable. Set it in your local environment, deployment platform Secret, or key management service, and keep only the variable name in source code.
OpenAI Python
Install or upgrade the official OpenAI Python SDK:
python -m pip install --upgrade openaiimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["KHAIX_API_KEY"],
base_url="https://api.khaix.net/v1",
)
response = client.responses.create(
model="gpt-5.6-sol",
input="Reply with: Python connected successfully",
)
print(response.output_text)If output_text is empty, print the complete response to inspect its events and output items. The Responses return structure does not include the choices used by Chat Completions.
OpenAI JavaScript
Run the following example in Node.js or a server-side route, with the key supplied through a backend environment variable.
npm install openaiimport OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.KHAIX_API_KEY,
baseURL: "https://api.khaix.net/v1",
});
const response = await client.responses.create({
model: "gpt-5.6-sol",
input: "Reply with: JavaScript connected successfully",
});
console.log(response.output_text);Anthropic Python
Install or upgrade the official Anthropic Python SDK. This SDK appends /v1/messages to the Base URL, so enter the site root here without /v1.
python -m pip install --upgrade anthropicimport os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["KHAIX_API_KEY"],
base_url="https://api.khaix.net",
)
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=256,
messages=[{"role": "user", "content": "Reply with: Python Messages connected successfully"}],
)
for block in message.content:
if block.type == "text":
print(block.text)Anthropic TypeScript
The following example uses the official Anthropic TypeScript SDK. Run it in Node.js, a server-side route, or another trusted server runtime.
npm install @anthropic-ai/sdkimport Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.KHAIX_API_KEY,
baseURL: "https://api.khaix.net",
});
const message = await client.messages.create({
model: "claude-sonnet-5",
max_tokens: 256,
messages: [{ role: "user", content: "Reply with: TypeScript Messages connected successfully" }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}Vercel AI SDK
Vercel AI SDK provides separate providers for Responses and generic OpenAI-compatible APIs. Use @ai-sdk/openai for Responses and @ai-sdk/openai-compatible for Chat Completions.
Responses provider
npm install ai @ai-sdk/openaiimport { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const khaix = createOpenAI({
apiKey: process.env.KHAIX_API_KEY,
baseURL: "https://api.khaix.net/v1",
});
const { text } = await generateText({
model: khaix.responses("gpt-5.6-sol"),
prompt: "Reply with: Vercel AI SDK connected successfully",
});
console.log(text);Chat Completions provider
npm install ai @ai-sdk/openai-compatibleimport { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const khaix = createOpenAICompatible({
name: "khaix",
apiKey: process.env.KHAIX_API_KEY,
baseURL: "https://api.khaix.net/v1",
});
const { text } = await generateText({
model: khaix("gpt-5.6-sol"),
prompt: "Reply with: Chat Completions connected successfully",
});
console.log(text);LangChain
ChatOpenAI from langchain-openai connects through Chat Completions. Standard text messages work directly; validate extended fields such as tools and structured output individually.
python -m pip install --upgrade langchain-openaiimport os
from langchain_openai import ChatOpenAI
model = ChatOpenAI(
model="gpt-5.6-sol",
api_key=os.environ["KHAIX_API_KEY"],
base_url="https://api.khaix.net/v1",
)
message = model.invoke("Reply with: LangChain connected successfully")
print(message.content)If you encounter parameter or streaming issues, first run the minimal Chat Completions request on the Text API page. If that request succeeds, check the LangChain version and supplied fields.
Production checklist
- Input scope: The text SDK examples send text only. Use the Image API for image generation and editing; do not treat
gpt-image-2as a chat model. - Keys: Use a separate key for each application, inject it through an environment variable or Secret, and prepare a rotation process.
- Protocol: Record whether the current call uses Responses or Chat Completions, and confirm it again after upgrading a provider.
- Timeouts and retries: Apply exponential backoff only to failures that can be safely retried, avoiding duplicate non-idempotent operations.
- Logs: Record request time, model, protocol, HTTP status, and request ID while filtering complete keys and sensitive prompts.
- Advanced capabilities: After basic text calls work, validate streaming, tools, and structured output separately.