Documentation navigation
On this page

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

SDKExample protocolBase URL
OpenAI PythonResponseshttps://api.khaix.net/v1
OpenAI JavaScriptResponseshttps://api.khaix.net/v1
Anthropic PythonAnthropic Messageshttps://api.khaix.net
Anthropic TypeScriptAnthropic Messageshttps://api.khaix.net
Vercel AI SDKExplicitly select Responses or Chat Completionshttps://api.khaix.net/v1
LangChain ChatOpenAIChat Completionshttps://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:

Terminal
python -m pip install --upgrade openai
Python · Responses
import 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.

Terminal
npm install openai
JavaScript · Responses
import 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.

Terminal
python -m pip install --upgrade anthropic
Python · Anthropic Messages
import 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.

Terminal
npm install @anthropic-ai/sdk
TypeScript · Anthropic Messages
import 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

Terminal
npm install ai @ai-sdk/openai
TypeScript · Responses
import { 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

Terminal
npm install ai @ai-sdk/openai-compatible
TypeScript · Chat Completions
import { 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.

Terminal
python -m pip install --upgrade langchain-openai
Python · Chat Completions
import 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-2 as 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.