---
title: "Vercel AI SDK createOpenAICompatible with a custom base URL"
description: "Call BroadNet Inference from the Vercel AI SDK with createOpenAICompatible from @ai-sdk/openai-compatible. generateText, streamText, tools and reasoning effort."
url: https://broadrouter.com/guides/vercel-ai-sdk-openai-compatible/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Use the Vercel AI SDK with BroadNet Inference

Updated 2026-11-16

Install ai and @ai-sdk/openai-compatible, then call createOpenAICompatible with name broadnet, baseURL https://inference.broadnet.ai/v1 and your BroadNet key as apiKey. Pass a BroadNet model ID such as broadnet/glm-5.3 to the provider, and use generateText or streamText as usual. Keep the key on the server, and give reasoning models a generous maxOutputTokens.

The [AI SDK](https://ai-sdk.dev/providers/openai-compatible-providers) from Vercel is a TypeScript toolkit for LLM apps. Its `@ai-sdk/openai-compatible` package creates a provider for any API that follows the OpenAI chat-completions format. BroadNet Inference does, so you only change the base URL, key and model IDs. For the plain OpenAI client instead, see [the Node SDK guide](https://broadrouter.com/guides/openai-node-sdk/).

## Setup

1.  **Install the packages.** At the time of writing, npm serves `ai` 7.x and `@ai-sdk/openai-compatible` 3.x.
    
    ```bash
    npm install ai @ai-sdk/openai-compatible
    export BROADNET_API_KEY='your-broadnet-key'
    ```
    
2.  **Create the provider.**
    
    ```ts
    // broadnet.ts
    import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
    
    export const broadnet = createOpenAICompatible({
      name: 'broadnet',
      baseURL: 'https://inference.broadnet.ai/v1',
      apiKey: process.env.BROADNET_API_KEY,
      includeUsage: true, // usage data in streaming responses
    });
    ```
    
3.  **Generate text.**
    
    ```ts
    import { generateText } from 'ai';
    import { broadnet } from './broadnet';
    
    const { text, usage, finishReason } = await generateText({
      model: broadnet('broadnet/glm-5.3'),
      prompt: 'Explain idempotency keys in two sentences.',
      maxOutputTokens: 4000, // reasoning counts toward this
    });
    
    console.log(text, finishReason, usage);
    ```
    
4.  **Stream it.** Swap `generateText` for `streamText` and read `textStream`. The [streaming guide](https://broadrouter.com/guides/streaming-chat-completions/) explains the wire format underneath.
    

The `name` you pass becomes the key for provider options and provider metadata, so keep it short and stable. `provider('id')` and `provider.chatModel('id')` both create a chat model; there is no separate setup per model. Keep the key on the server. Don’t import this file into code that runs in the browser, or the key ships to every visitor.

The provider docs list text generation, streaming, tool calling, structured outputs, reasoning content and image input as supported capabilities, with the note that some depend on the provider. On BroadNet, image input works with DeepSeek V4.1 Flash, Qwen3.8 27B and Gemma 4 VL 26B. GLM 5.3 takes text only.

## Options worth setting

-   **reasoningEffort.** Pass it through `providerOptions`, keyed by the provider name. The AI SDK docs say the exact values depend on the provider; BroadNet’s docs show `low`.

```ts
const result = await generateText({
  model: broadnet('broadnet/deepseek-v4.1-flash'),
  prompt: 'Classify: "refund my order" -> intent?',
  providerOptions: { broadnet: { reasoningEffort: 'low' } },
});
```

-   **supportsStructuredOutputs.** The AI SDK only sends JSON schemas when this is `true` on the provider. BroadNet lists structured output for GLM 5.3 and Qwen3.8 27B. If you turn it on, use those models for schema output.
-   **maxRetries.** `generateText` retries twice by default. Set it to fit your rate limit.
-   **Reasoning output.** The AI SDK reads reasoning content when the provider returns it. The top-level `reasoningText` result field is now marked deprecated in favour of `finalStep.reasoningText`. Don’t build logic that depends on reasoning being present.

## Which model to pick

| Need | Model | Context |
| --- | --- | --- |
| Tool calling, structured output | [`broadnet/glm-5.3`](https://broadrouter.com/models/glm-5.3/) | 1,048,576 |
| Images plus tools, Arabic | [`broadnet/qwen3.8-27b`](https://broadrouter.com/models/qwen3.8-27b/) | 262,144 |
| Long context, flat-rate plan | [`broadnet/deepseek-v4.1-flash`](https://broadrouter.com/models/deepseek-v4.1-flash/) | 1,048,576 |
| Cheap text and image calls | [`broadnet/gemma-4-26b-a4b`](https://broadrouter.com/models/gemma-4-vl-26b/) | 32,768 |

Per-token prices for each model are on the [pricing page](https://broadrouter.com/pricing/).

## Troubleshooting

-   **401.** `BROADNET_API_KEY` is missing in the runtime (check your hosting provider’s env settings), wrong, expired, or out of pay-as-you-go allowance.
-   **providerOptions ignored.** The key must match the provider `name` in camelCase. With `name: 'broadnet'`, use `providerOptions.broadnet`.
-   **Model errors.** The ID must match BroadNet’s exactly, with the `broadnet/` prefix. GLM 5.3, Qwen3.8 27B and DeepSeek V4.1 Flash need a top-up; the $5 starting credit covers Gemma 4 VL 26B and the two Transcribe models.
-   **Empty text, finishReason “length”.** Reasoning used the budget. Raise `maxOutputTokens` or lower `reasoningEffort`. [Why answers come back empty](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **429 under load.** A pay-as-you-go key allows 30 requests a minute and 4 in flight. Serverless functions scale out fast, so cap concurrency in your app. See [errors and retries](https://broadrouter.com/guides/errors-and-retries/).
-   **Agents in parallel on a plan key.** One [unlimited plan session](https://broadrouter.com/guides/unlimited-llm-api-sessions/) runs one request at a time. Running `Promise.all` over several agents needs one session per agent, or the requests queue.

## Terms in this guide

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Structured output](https://broadrouter.com/glossary/structured-output/)

Structured output is an LLM API feature that constrains a model's reply to a format the developer specifies, usually a JSON Schema, so code can parse it reliably. It is stricter than JSON mode, which guarantees valid JSON but not a particular shape.

[Tool calling](https://broadrouter.com/glossary/tool-calling/)

Tool calling, also called function calling, is an LLM API feature in which the model returns a structured request to run a function the developer has defined, with JSON arguments. The application runs the function and sends the result back; the model never runs code itself.

[Concurrency](https://broadrouter.com/glossary/concurrency/)

Concurrency is the number of requests a client has in flight at the same time. LLM APIs often cap it per key or plan, separately from requests per minute, because each open request holds GPU capacity until its response has finished.

[Rate limit](https://broadrouter.com/glossary/rate-limit/)

A rate limit is a cap an API places on how much a client can use it in a time window, such as requests per minute or tokens per minute. Requests over the limit are refused, usually with HTTP 429 Too Many Requests, until usage falls back under it.

[Streaming](https://broadrouter.com/glossary/streaming/)

Streaming is a way of returning a language model response in small chunks while it is still being generated, instead of as one reply at the end. OpenAI-compatible APIs stream over server-sent events when the request sets stream to true.

[Base URL](https://broadrouter.com/glossary/base-url/)

A base URL is the fixed root address of an API, such as https://api.example.com/v1, that a client puts in front of every endpoint path, such as /chat/completions. In OpenAI-compatible SDKs, changing the base URL, together with the API key and model ID, points the same code at a different provider.

[JSON Schema](https://broadrouter.com/glossary/json-schema/)

JSON Schema is a vocabulary, written in JSON, for describing and validating the structure of JSON data: types, required fields, allowed values and nesting. The current version is 2020-12. LLM APIs use it to define tool parameters and the exact shape a structured output must follow.

## Questions

### Should I use @ai-sdk/openai or @ai-sdk/openai-compatible?

Use @ai-sdk/openai-compatible for third-party OpenAI-compatible APIs. It calls the chat completions endpoint, which is what BroadNet Inference serves.

### Why is the generated text empty?

Reasoning counts toward max\_tokens on BroadNet. If maxOutputTokens is small, the model can use it all before the answer starts. Raise it or set reasoningEffort to low.

### How do I get token usage while streaming?

Set includeUsage to true when you create the provider. The AI SDK docs say it adds usage data to streaming responses. It defaults to false.

### Do I need a separate setup for each BroadNet model?

No. One createOpenAICompatible provider covers every model. Call broadnet('model-id') or broadnet.chatModel('model-id') with any BroadNet chat model ID.

## Related guides

-   [Use the OpenAI Node.js SDK with BroadNet Inference](https://broadrouter.com/guides/openai-node-sdk/)
-   [Stream chat completions and handle dropped connections](https://broadrouter.com/guides/streaming-chat-completions/)
-   [Why a reasoning model returns an empty answer](https://broadrouter.com/guides/reasoning-tokens-empty-response/)
-   [Add BroadNet Inference to opencode as a custom provider](https://broadrouter.com/guides/opencode-custom-provider/)
-   [All tools that work with BroadNet Inference](https://broadrouter.com/integrations/): SDKs, coding agents, chat UIs and automation tools, with exact settings for each

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-vercel-ai-sdk-openai-compatible&utm_content=page-cta) ·

**Sources**

-   [AI SDK docs, OpenAI Compatible providers (checked 2026-11-14)](https://ai-sdk.dev/providers/openai-compatible-providers)
-   [AI SDK docs, generateText reference (checked 2026-11-14)](https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-text)
-   [npm, @ai-sdk/openai-compatible package (3.x, checked 2026-11-14)](https://www.npmjs.com/package/@ai-sdk/openai-compatible)
-   [BroadNet Inference API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-vercel-ai-sdk-openai-compatible&utm_content=sources)
