Reference
SDKs & frameworks
No ThaiRouter SDK to install. Anything that speaks OpenAI works.
Every integration below is the stock library with two settings changed: the base URL and the key. Model ids are the ThaiRouter ids from the catalog.
OpenAI Python
pip install openai
from openai import OpenAI
client = OpenAI(base_url="https://api.thairouter.ai/v1", api_key="sk-tr-...")
r = client.chat.completions.create(
model="thairouter/glm-5.3-flash",
messages=[{"role": "user", "content": "สวัสดี"}],
)
print(r.choices[0].message.content)
print(r.model_extra["thairouter"]) # {'usage_id': '…', 'cost': 0.0007}OpenAI Node
npm i openai
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.thairouter.ai/v1", apiKey: process.env.THAIROUTER_KEY });
const r = await client.chat.completions.create({
model: "thairouter/glm-5.3-flash",
messages: [{ role: "user", content: "สวัสดี" }],
});
console.log(r.choices[0].message.content);
console.log((r as unknown as { thairouter: { usage_id: string; cost: number } }).thairouter);Vercel AI SDK
Use the OpenAI-compatible provider. Streaming, useChat and route handlers work unchanged.
npm i ai @ai-sdk/openai-compatible
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";
const thairouter = createOpenAICompatible({
name: "thairouter",
baseURL: "https://api.thairouter.ai/v1",
apiKey: process.env.THAIROUTER_KEY,
});
const result = streamText({
model: thairouter("thairouter/glm-5.3-flash"),
prompt: "สรุปข้อดีของ connection pooling",
});
for await (const chunk of result.textStream) process.stdout.write(chunk);LangChain
Python · pip install langchain-openai
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="thairouter/glm-5.3-flash",
base_url="https://api.thairouter.ai/v1",
api_key="sk-tr-...",
max_tokens=1024,
)
print(llm.invoke("สวัสดี").content)TypeScript · npm i @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "thairouter/glm-5.3-flash",
apiKey: process.env.THAIROUTER_KEY,
configuration: { baseURL: "https://api.thairouter.ai/v1" },
});
const res = await llm.invoke("สวัสดี");
console.log(res.content);LiteLLM
Prefix the model with openai/ so LiteLLM uses the OpenAI adapter, and pass the base URL.
pip install litellm
import litellm
r = litellm.completion(
model="openai/thairouter/glm-5.3-flash",
api_base="https://api.thairouter.ai/v1",
api_key="sk-tr-...",
messages=[{"role": "user", "content": "สวัสดี"}],
)
print(r.choices[0].message.content)Environment variables
The OpenAI SDKs read these automatically, so existing code can switch with no edits at all.
export OPENAI_BASE_URL="https://api.thairouter.ai/v1"
export OPENAI_API_KEY="sk-tr-..."Tools that only accept
OPENAI_API_KEY and a base URL (Cursor, Continue, Open WebUI, aider, most CLI agents) work the same way. If one refuses unknown model ids, add thairouter/glm-5.3-flash to its model list.