---
title: "Uncensored models with the AI SDK OpenAI compatible provider"
canonical: https://unrestrictable.ai/guides/ai-sdk
generated: 2026-11-16T02:57:39.029Z
source: https://unrestrictable.ai/guides/ai-sdk
base_url: https://api.unrestrictable.ai/v1
---

# Wire the AI SDK to an uncensored model

One createOpenAICompatible call on our base URL, then generateText, streamText, tool() and a Next.js route on an uncensored build, with the live cost of a call.

Steps checked November 2, 2026 · prices as of November 16, 2026

A single `createOpenAICompatible` call connects the AI SDK to every model in this catalog. Below: the provider, then `generateText`, `streamText` and `tool()` on an uncensored build, which builds accept tool calls, a Next.js route, the error codes, and the live price of one call.

## What you need

- Node with pnpm or npm.
- A key from the [console](https://app.unrestrictable.ai/console): it starts with `sk-unr-`, shows once, and spends a prepaid balance opened from $10 by card, WeChat Pay or crypto.
- A model id from the [models page](https://unrestrictable.ai/models).

To see a build answer before installing anything, open [/chat](https://unrestrictable.ai/chat): the same models, in the browser, with free turns each day.

## Install and set the key

`ai` is the SDK; `@ai-sdk/openai-compatible` is its provider for endpoints that answer in the OpenAI Chat Completions shape. `zod` is only for the tool example.

```bash
pnpm add ai @ai-sdk/openai-compatible zod
# or
npm install ai @ai-sdk/openai-compatible zod
```

Keep the key in an environment variable so it never appears in source.

```bash
export UNRESTRICTABLE_API_KEY="sk-unr-live-…"
```

## Build the provider

Hand `createOpenAICompatible` a `name`, our `baseURL` and the `apiKey`. Leave the URL ending at `/v1`; the SDK appends `/chat/completions` itself. Turn on `includeUsage` so streamed replies report token counts too; the cost section below relies on those numbers.

```javascript
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

export const uncensored = createOpenAICompatible({
  name: 'unrestrictable',
  baseURL: 'https://api.unrestrictable.ai/v1',
  apiKey: process.env.UNRESTRICTABLE_API_KEY,
  includeUsage: true, // token counts on streams as well
});
```

- name: unrestrictable a label of your choosing; it is the provider key inside providerOptions
- baseURL: https://api.unrestrictable.ai/v1 stops at /v1, with no path after it
- apiKey: process.env.UNRESTRICTABLE_API_KEY goes out as Authorization: Bearer
- model: uncensored('glm-5.3-uncensored') any id on the models page; provider.chatModel(id) does the same thing

The identical base URL and key serve every other client that talks this format, the [OpenAI SDKs](https://unrestrictable.ai/guides/sdks) among them.

## A first answer with generateText

Calling the provider with an id, `provider('model-id')`, gives you a chat model to pass as `model`. Back comes `text`, `finishReason` and a `usage` object whose `inputTokens`, `outputTokens` and `totalTokens` are what you were charged for.

```javascript
import { generateText } from 'ai';
import { uncensored } from './provider';

const { text, usage, finishReason } = await generateText({
  model: uncensored('glm-5.3-uncensored'),
  prompt: 'Explain how a lock pick works, step by step.',
});

console.log(text);
console.log(usage.inputTokens, usage.outputTokens, usage.totalTokens, finishReason);
```

## Streaming with streamText

`streamText` returns immediately. Read `textStream` to get each piece as it is written; `result.usage` is a promise that settles when the stream closes.

```javascript
import { streamText } from 'ai';
import { uncensored } from './provider';

const result = streamText({
  model: uncensored('glm-5.3-flash-uncensored'),
  prompt: "Write a villain's monologue.",
});

for await (const piece of result.textStream) process.stdout.write(piece);

const usage = await result.usage; // settles once the stream closes; requires includeUsage on the provider
console.log(usage.inputTokens, usage.outputTokens);
```

Inside a Next.js route handler, send back `result.toTextStreamResponse()` for raw text, or `result.toUIMessageStreamResponse()` when the client uses `useChat`.

```javascript
// app/api/chat/route.ts
import { streamText } from 'ai';
import { uncensored } from '@/lib/provider';

export async function POST(req: Request) {
  const { prompt } = (await req.json()) as { prompt: string };
  const result = streamText({
    model: uncensored('glm-5.3-uncensored'),
    prompt,
  });
  return result.toTextStreamResponse();
}
```

## Tools

A `tool()` bundles three things: a description, an `inputSchema`, and the `execute` function that runs. Setting `stopWhen: isStepCount(5)` allows the SDK to run the tool, feed the result back and continue, for at most five rounds. Every call and its result lands in `steps`.

```javascript
import { generateText, isStepCount, tool } from 'ai';
import { z } from 'zod';
import { uncensored } from './provider';

const { text, steps } = await generateText({
  model: uncensored('glm-5.3-uncensored'),
  tools: {
    weather: tool({
      description: 'Get the weather in a location',
      inputSchema: z.object({
        location: z.string().describe('The location to get the weather for'),
      }),
      execute: async ({ location }) => ({ location, temperature: 72 }),
    }),
  },
  stopWhen: isStepCount(5), // run tools for at most 5 steps
  prompt: 'What is the weather in San Francisco?',
});

const toolCalls = steps.flatMap((step) => step.toolCalls);
console.log(toolCalls.length, text);
```

Tool calls only work on a build whose base model learned them. The catalog lists `tools` under a build’s parameters only when each of its routes accepts tool calls; on 2026-11-16, 40 listed builds carry it, and the [agent tools](https://unrestrictable.ai/features/agent-tools) page lists each of them. None of the builds on this page publish that field on 2026-11-16; take a build from that list for tool work and use these for text.

- nemotron-3-ultra-550b-a55b-uncensored: takes tool calls Nemotron 3 Ultra 550B Uncensored
- abliterated-model-large-flash: takes tool calls Abliterated Large Flash
- abliterated-model-large: takes tool calls Abliterated Model Large
- abliterated-model-large-v2: takes tool calls Abliterated Model Large V2

The gateway also has built-in tools (web search, page fetch, a remote MCP server, a code sandbox) that run inside the request when declared in its `tools` array; the [agent tools](https://unrestrictable.ai/features/agent-tools) page describes each.

## The price of a call

Take a call of 2,000 input and 400 output tokens, roughly a system prompt plus a short exchange. On four builds, at the catalog prices of 2026-11-16:

| Model | One call | 1,000 calls |
| --- | --- | --- |
| [GLM-5.3 Uncensored](https://unrestrictable.ai/models/glm-5.3-uncensored) | $0.0009 | $0.90 |
| [GLM-5.3 Abliterated](https://unrestrictable.ai/models/glm-5.3-abliterated) | $0.0061 | $6.11 |
| [DeepSeek V4.1 Flash Abliterated](https://unrestrictable.ai/models/deepseek-v4.1-flash-abliterated) | $0.0024 | $2.38 |
| [GLM-5.3 Flash Uncensored](https://unrestrictable.ai/models/glm-5.3-flash-uncensored) | $0.00036 | $0.36 |

To check a bill, take `usage.inputTokens` and `usage.outputTokens` from each result and multiply them by the per-million prices in this table.

| Model | Build | Input $/M | Output $/M |
| --- | --- | --- | --- |
| [GLM-5.3 Uncensored](https://unrestrictable.ai/models/glm-5.3-uncensored) glm-5.3-uncensored | Uncensored | $0.282 | $0.846 |
| [GLM-5.3 Abliterated](https://unrestrictable.ai/models/glm-5.3-abliterated) glm-5.3-abliterated | Abliterated | $2.1825 | $4.365 |
| [DeepSeek V4.1 Flash Abliterated](https://unrestrictable.ai/models/deepseek-v4.1-flash-abliterated) deepseek-v4.1-flash-abliterated | Abliterated | $0.8488 | $1.6975 |
| [GLM-5.3 Flash Uncensored](https://unrestrictable.ai/models/glm-5.3-flash-uncensored) glm-5.3-flash-uncensored | Uncensored | $0.1053 | $0.3685 |

Prices per million tokens, read from the live catalog on 2026-11-16.

## Confirm the setup

Listing the models costs nothing and confirms both the key and the base URL. The response holds exactly the ids this key may use.

```bash
curl https://api.unrestrictable.ai/v1/models -H "Authorization: Bearer sk-unr-live-…"
```

Every reply carries a request id header; a non-streamed one also carries its charge in USD. The console’s usage page shows both, and the [docs page](https://unrestrictable.ai/docs) covers the rest of the API.

## When it fails

- `401 invalid_api_key`: the key is mistyped or has been revoked. Copy a fresh one from the console and confirm the variable name the provider reads.
- `402 insufficient_balance`: not enough credit for this request; top up in the console. `402 monthly_limit_reached`: the key reached the monthly spend cap you gave it.
- `403 scope_denied`: the key is scoped to specific models, and this id is outside that scope.
- `404 model_not_found`: the id inside `uncensored(‘…’)` does not exist on the [models page](https://unrestrictable.ai/models). Compare the spelling, and remember a display name is not an id.
- `429 rate_limited`: the key is over its rate limit. A `retry-after` header says how long to wait.
- Nothing is charged for a request that fails before the model starts answering.

## Questions

### Does the provider use Chat Completions or the Responses API?

Chat Completions, which every listed build answers. Since the catalog also lists /v1/responses on the builds here, the @ai-sdk/openai package reaches them as well: its default openai(id) goes through the Responses API, while openai.chat(id) stays on Chat Completions.

### Why @ai-sdk/openai-compatible and not @ai-sdk/openai with a baseURL?

Either one works. The compatible provider was built for endpoints like ours: Chat Completions out of the box, includeUsage for streamed token counts, providerOptions for extra request fields. With @ai-sdk/openai, use its .chat() factory. See the OpenAI SDK guide.

### Can OpenCode use the same setup?

Yes. OpenCode is built on the AI SDK, and its config accepts a custom provider that speaks the OpenAI format, so the base URL, the key and the model ids carry over unchanged. See the OpenCode guide.

### What does a streaming Next.js route look like?

In the POST handler, call streamText and return result.toTextStreamResponse() for plain text, or result.toUIMessageStreamResponse() if the page uses useChat. The route snippet above is complete as written.

Every model above is on the [uncensored model list](https://unrestrictable.ai/models) with its live price per million tokens. [Per-token pricing](https://unrestrictable.ai/pricing) sets the whole catalog side by side, and the [family directory](https://unrestrictable.ai/uncensored) groups the builds by base model.

[Get a key](https://app.unrestrictable.ai/console) Prepaid from $10, no subscription.

## New models and price changes, once a month.

New uncensored builds with their prices, price moves, and what the daily model check found.
