---
title: "AI SDK OpenAI compatible provider for pentest models"
canonical: https://pentestllm.ai/guides/ai-sdk
generated: 2026-11-18T03:35:59.457Z
source: https://pentestllm.ai/guides/ai-sdk
base_url: https://api.pentestllm.ai/v1
---

# Point the AI SDK OpenAI-compatible provider at a pentest model

createOpenAICompatible once, then generateText, streamText and tool() against an uncensored build: tool support, usage fields, a Next.js route, errors, cost.

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

If you are writing your own tooling on the AI SDK, a triage script, a report drafter, a scope-aware agent, one `createOpenAICompatible` call puts every build in this catalog behind it, including the security-tuned ones that answer questions a stock model refuses. Below: the provider, then `generateText`, `streamText` and `tool()` against an uncensored build, tool support per build, a Next.js handler, the error codes and the live cost of a call.

## What you need

Install `ai` and `@ai-sdk/openai-compatible`, the provider package for any server that answers OpenAI Chat Completions. `zod` only matters for the scope-lookup tool later on.

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

Create the key in the [console](https://app.pentestllm.ai/console). It begins with `sk-ptl-`, you see it once, and it draws on prepaid credit you add from $10. Export it as a variable so no source file carries it.

```bash
export PENTESTLLM_API_KEY="sk-ptl-live-…"
```

## Build the provider

Three arguments go into `createOpenAICompatible`: a `name`, this API’s `baseURL` and your `apiKey`. Stop the URL at `/v1`, since the SDK appends `/chat/completions` itself. Set `includeUsage` or streamed answers come back without token counts, and the cost section further down needs them.

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

export const uncensored = createOpenAICompatible({
  name: 'pentestllm',
  baseURL: 'https://api.pentestllm.ai/v1',
  apiKey: process.env.PENTESTLLM_API_KEY,
  includeUsage: true, // usage in streaming responses too
});
```

- name: pentestllm free text; the key under which providerOptions addresses this provider
- baseURL: https://api.pentestllm.ai/v1 stops at /v1
- apiKey: process.env.PENTESTLLM_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

The same URL and key work in the plain [OpenAI SDKs](https://pentestllm.ai/guides/sdks) and in every other client that speaks this format. For a try without installing anything, the prompt box on the home page gives a few free turns, and the [playground](https://pentestllm.ai/playground) runs any build once you have a key.

## First reply with generateText

Calling the provider with an id gives you a chat model object for the `model` field. Back come `text`, `finishReason` and a `usage` object whose `inputTokens`, `outputTokens` and `totalTokens` are exactly what you were charged for. The sample question is one a stock model often declines; the builds here answer it.

```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 JWT alg=none bypass works and how to test for it on an in-scope login endpoint.',
});

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

## Streaming, and a route handler

`streamText` does not wait for the model. Read `textStream` piece by piece, then await `result.usage`, which settles once the last chunk arrives. Report drafts are where streaming pays off: the tester reads while the model writes.

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

const result = streamText({
  model: uncensored('glm-5.3-flash-uncensored'),
  prompt: 'Draft the executive summary of a web app pentest report: two criticals, one high, remediation first.',
});

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

const usage = await result.usage; // resolves when the stream ends; needs includeUsage on the provider
console.log(usage.inputTokens, usage.outputTokens);
```

Inside a Next.js route, hand back `result.toTextStreamResponse()` when the client wants raw text, or `result.toUIMessageStreamResponse()` when it 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();
}
```

## Tool calls

A `tool()` is a description, an `inputSchema` and an `execute` function. With `stopWhen: isStepCount(5)` the SDK runs whatever the model asks for, feeds the result back and repeats, five rounds at most. `steps` keeps every call and result. The example gives the model a scope lookup, the kind of guardrail an engagement agent should have before it touches a host.

```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: {
    scope: tool({
      description: 'Look up a host in the engagement scope file',
      inputSchema: z.object({
        host: z.string().describe('The hostname or IP to check'),
      }),
      execute: async ({ host }) => ({ host, inScope: true, notes: 'prod web tier, test window 02:00-06:00 UTC' }),
    }),
  },
  stopWhen: isStepCount(5), // keep calling tools for up to 5 steps
  prompt: 'Is app.example.test in scope, and when may I test it?',
});

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

Tool use depends on the base model having learned it. When every route of a build accepts tool calls, the catalog adds `tools` to its supported parameters; on 2026-11-17 that is true of 41 listed builds. The [agent tools](https://pentestllm.ai/features/agent-tools) page lists each of them. None of the builds on this page publishes that field on 2026-11-17, so take an id from that list for agent work and use these for plain answers.

- 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

Separate from your own tools, the gateway offers built-in ones: web search and fetch, a remote MCP server, a code sandbox. You declare them in the request’s `tools` array and they run within that single request; the [agent tools](https://pentestllm.ai/features/agent-tools) page covers them.

## Cost per call

Take a call of 2,000 input tokens and 400 output tokens, about what a system prompt plus a short exchange comes to. At the catalog prices of 2026-11-17, the four builds cost:

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

To reconcile an invoice, take `usage.inputTokens` and `usage.outputTokens` from each result and multiply by the per-million rates in this table.

| Model | Build | Input $/M | Output $/M |
| --- | --- | --- | --- |
| [GLM-5.3 Uncensored](https://pentestllm.ai/models/glm-5.3-uncensored) glm-5.3-uncensored | Uncensored | $0.282 | $0.846 |
| [GLM-5.3 Abliterated](https://pentestllm.ai/models/glm-5.3-abliterated) glm-5.3-abliterated | Abliterated | $2.1825 | $4.365 |
| [DeepSeek V4.1 Flash Abliterated](https://pentestllm.ai/models/deepseek-v4.1-flash-abliterated) deepseek-v4.1-flash-abliterated | Abliterated | $0.8488 | $1.6975 |
| [GLM-5.3 Flash Uncensored](https://pentestllm.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-17.

## Prove the key works

Listing models costs nothing and confirms both the key and the URL. The ids that come back are the ones this key may call.

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

Each response carries a request id header, and a non-streamed response also carries its charge in USD. Both show on the usage page of the console; the rest of the API is on the [docs page](https://pentestllm.ai/docs).

## When it fails

- `401 invalid_api_key`: a wrong or revoked key, or the provider reading a variable you never set. Recopy the key and check the variable name.
- `402 insufficient_balance`: not enough credit for this request; add some in the console. `402 monthly_limit_reached`: the monthly cap you put on the key is used up.
- `403 scope_denied`: the key was restricted to a set of models that does not include this one.
- `404 model_not_found`: whatever you passed to `uncensored(‘…’)` is not an id on the [models page](https://pentestllm.ai/models). Ids are not display names; compare the spelling.
- `429 rate_limited`: the key’s rate limit tripped. Wait as long as `retry-after` says.
- Nothing is charged for a request that fails before a model answers.

## Questions

### Which route does the provider send to, Chat Completions or Responses?

Chat Completions, and every listed build answers it. The builds on this page also list /v1/responses in the catalog, so @ai-sdk/openai works as well: its default openai(id) takes the Responses route, and openai.chat(id) stays on Chat Completions.

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

It works through openai.chat(id). The compatible provider fits a third-party endpoint better: Chat Completions is its default, includeUsage adds counts to streams, and providerOptions carries any extra request field. See the OpenAI SDK guide.

### OpenCode is built on the AI SDK. Same setup?

Same values. OpenCode accepts a custom OpenAI-compatible provider in its config, with this base URL, your key and the model ids unchanged. See the OpenCode guide.

### What goes in the Next.js route for streaming?

streamText inside the POST handler, then return result.toTextStreamResponse() for text or result.toUIMessageStreamResponse() for a useChat client. The route snippet above is complete.

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

[Get a key](https://app.pentestllm.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.
