Integrations
Development SDKs
Point a supported SDK's Base URL to KHaiXAPI to connect text generation models through its protocol. 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. After a basic text request works, test tools and structured output separately.
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.
Use Grok models
In an existing configuration that supports OpenAI Responses or Chat Completions, replace the model name with an available text model ID from Model Plaza; for example, use grok-4.5 when that model is currently available. Keep the Base URL, API key, protocol, and response handling required by the selected SDK. Basic calls need no additional SDK or endpoint configuration.
Use China models
In an existing configuration that supports OpenAI Responses or Chat Completions, replace the model name with an available text model ID in Model Plaza to try models from the Chinese Model Pool. Keep the Base URL, API key, protocol, and response handling required by the selected SDK. Basic calls need no additional SDK or endpoint configuration.
Production checklist
- Input scope: The text SDK examples send text only. Use the Image Generation 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.