The AI SDK has a provider made for OpenAI-compatible APIs. It is the simplest way to use Chainless from Next.js, Node or edge runtimes.
Recommended: @ai-sdk/openai-compatible
npm install ai @ai-sdk/openai-compatibleimport { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";
const chainless = createOpenAICompatible({
name: "chainless",
baseURL: "https://chainless.one/v1",
apiKey: process.env.CHAINLESS_API_KEY,
includeUsage: true,
});
const result = streamText({
model: chainless("kimi-k3.1-pro-uncensored"),
prompt: "Draft a responsible disclosure email for an IDOR in a customer portal.",
});
for await (const part of result.textStream) process.stdout.write(part);
console.log(await result.usage);The key is sent as Authorization: Bearer. includeUsage defaults to false; turn it on to get token counts from streams.
Alternative: @ai-sdk/openai with .chat()
import { createOpenAI } from "@ai-sdk/openai";
const chainless = createOpenAI({ name: "chainless", baseURL: "https://chainless.one/v1", apiKey: process.env.CHAINLESS_API_KEY });
const model = chainless.chat("glm-5.3-fast-uncensored"); // not chainless("…"): that targets /responsescreateOpenAI also reads OPENAI_BASE_URL and OPENAI_API_KEY from the environment, which is easy to mix up with a real OpenAI setup. The compatible provider avoids that.
In a Next.js app
Create the provider in server code only (a route handler or server action) and stream the result to the client with the AI SDK UI helpers of your installed version. Keep the key on the server. Model ids and limits: /models; request details: /docs/api.
Sources
Checked against the official documentation on 2026-11-29. Tools change their settings often; if a field moved, the source below is the reference.