Vercel AI SDK
Vercel AI SDK with an OpenAI-compatible uncensored API
Create an Abliterator provider with @ai-sdk/openai-compatible, then use generateText, streamText, multi-step tools with stopWhen and typed Output.object results.
Create the provider with createOpenAICompatible({ name: "Abliterator", baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY, includeUsage: true }) and pass Abliterator("kimi-k3.1-pro-abliterated") as the model.
The AI SDK talks to any Chat Completions server through the @ai-sdk/openai-compatible provider. You create it once with Abliterator's base URL and key, then call it with a model ID. These snippets were type-checked with tsc --strict and run on Node 22 with ai 7.0 and @ai-sdk/openai-compatible 3.0.
Install
npm install ai @ai-sdk/openai-compatible zod
export ABL_API_KEY="sk-abl-v1-..."
Create the provider and generate text
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const abliterator = createOpenAICompatible({
name: "abliterator",
baseURL: "https://abliterator.ai/v1",
apiKey: process.env.ABL_API_KEY,
includeUsage: true,
supportsStructuredOutputs: true,
});
const { text, usage } = await generateText({
model: abliterator("kimi-k3.1-pro-abliterated"),
system: "You are a penetration tester writing for the client's engineering team.",
prompt: "Explain why the IDOR we found in /api/invoices/{id} is high severity and how to fix it.",
maxOutputTokens: 1024,
});
console.log(text);
console.log(usage);
Abliterator's per-request cost (USD) is not a standard AI SDK field, but it is kept in usage.raw.cost. supportsStructuredOutputs: true tells the SDK it may send response_format with a JSON schema, which Abliterator passes to the model. abliterator("...") is shorthand for abliterator.chatModel("...").
Stream text
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";
const abliterator = createOpenAICompatible({
name: "abliterator",
baseURL: "https://abliterator.ai/v1",
apiKey: process.env.ABL_API_KEY,
includeUsage: true,
});
const result = streamText({
model: abliterator("deepseek-v4.1-flash-abliterated"),
prompt: "Write a tabletop exercise scenario for a supply-chain compromise of a CI pipeline.",
});
for await (const delta of result.textStream) {
process.stdout.write(delta);
}
console.log("\n", await result.usage);
streamText returns immediately; errors surface while you iterate or through the onError callback. In a route handler, return result.toTextStreamResponse() sends the stream to the browser (Next.js example).
Multi-step tool calls
Tools are declared with tool() and a Zod inputSchema. stopWhen: stepCountIs(n) lets the SDK run the tool, feed the result back and ask the model again, up to n steps:
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";
const abliterator = createOpenAICompatible({ name: "abliterator", baseURL: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY });
const result = await generateText({
model: abliterator("kimi-k3.1-pro-abliterated"),
tools: {
getAlert: tool({
description: "Fetch an alert from the SIEM by ID.",
inputSchema: z.object({ alertId: z.string() }),
execute: async ({ alertId }) => ({
alertId,
rule: "Impossible travel",
user: "j.doe",
logins: ["Berlin 08:02", "Singapore 08:19"],
}),
}),
},
stopWhen: stepCountIs(4),
prompt: "Triage alert A-1042 and say whether to reset the user's session.",
});
console.log(result.text);
console.log(result.steps.map((s) => s.toolCalls.map((c) => c.toolName)));
Typed output
Output.object validates the final answer against a Zod schema:
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText, Output } from "ai";
import { z } from "zod";
const abliterator = createOpenAICompatible({
name: "abliterator",
baseURL: "https://abliterator.ai/v1",
apiKey: process.env.ABL_API_KEY,
supportsStructuredOutputs: true,
});
const { output } = await generateText({
model: abliterator("kimi-k3.1-pro-abliterated"),
output: Output.object({
schema: z.object({
category: z.enum(["phishing", "malware", "fraud", "benign"]),
confidence: z.number(),
rationale: z.string(),
}),
}),
prompt: "Label this message for a trust-and-safety dataset: 'Final notice: your parcel is held, pay the $1.99 fee at hxxps://parcel-fee[.]info'",
});
console.log(output.category, output.confidence);
Troubleshooting
- 404 on
/v1/responses. The model came from@ai-sdk/openai(openai("...")orcreateOpenAI). That provider defaults to the Responses API. UsecreateOpenAICompatible. usagehas undefined token counts on streams. AddincludeUsage: trueto the provider.- Structured output falls back to JSON in the prompt. Without
supportsStructuredOutputs: true, the provider does not send a JSON schema, and you get a warning inresult.warnings. Turn the flag on. - Provider options are silently ignored. The
providerOptionskey must be the providernameyou chose (abliteratorhere) oropenaiCompatible. Options under any other key, such asopenai, are dropped. - Agent loops end after one step. Without
stopWhen,generateTextstops after the first tool call. SetstopWhen: stepCountIs(n).
Frequently asked questions
Should I use @ai-sdk/openai or @ai-sdk/openai-compatible?
Use @ai-sdk/openai-compatible. The @ai-sdk/openai provider calls the Responses API by default, which Abliterator does not serve, while the compatible provider always calls Chat Completions.
How do I pass reasoning_effort through the AI SDK?
Use providerOptions keyed by the provider name you chose, for example providerOptions: { Abliterator: { reasoningEffort } }, using a value from the Abliterator reasoning guide. The compatible provider sends it as the reasoning_effort request field.
Why is usage empty after streamText?
The compatible provider only asks for usage in streams when includeUsage is true. Set it on createOpenAICompatible and await result.usage after the stream finishes.