Vercel AI SDK
Using Infron with Vercel AI SDK
Infron exposes an OpenAI-compatible API that can be used with the Vercel AI SDK through @ai-sdk/openai-compatible.
This guide shows how to configure the provider, run text generation, stream responses, use tool calling, enable request debugging, and pass Anthropic-specific tool options when needed.
Install
npm install ai @ai-sdk/openai-compatible zodEnvironment
export INFRON_API_KEY="your-infron-api-key"Do not expose this key in browser code. Use it from a server route, API route, or backend service.
Basic Setup
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
const infron = createOpenAICompatible({
name: 'infron',
baseURL: 'https://llm.onerouter.pro/v1',
apiKey: process.env.INFRON_API_KEY,
});Generate Text
Stream Text
Next.js Route Handler
Tool Calling
The Vercel AI SDK standardizes tool definitions into OpenAI-compatible tool schemas.
Debugging Requests
Infron supports request and response debugging fields. They are useful when validating how an OpenAI-compatible request is mapped to an upstream provider request.
Pass debug_request and debug_response through providerOptions.infron.
When enabled, Infron responses may include debug_info.request and debug_info.response in the response body. Use these fields for development and validation only. Avoid logging them in production if prompts or payloads may contain sensitive data.
Anthropic-Specific Tool Options
Some Anthropic features use fields that are not part of the standard OpenAI tool schema, such as:
defer_loadingeager_input_streamingtool-level
cache_control
The Vercel AI SDK does not preserve arbitrary per-tool Anthropic fields by default because it normalizes tools into the OpenAI-compatible format.
To send these fields through Infron, use transformRequestBody on the OpenAI-compatible provider and inject the Anthropic-native fields into the final request body.
Use the provider with providerOptions.infron.anthropic_tool_options:
Last updated