@api-route/ai-sdk-provider
v0.1.0
Published
API Route community provider for the Vercel AI SDK
Maintainers
Readme
API Route Provider for the Vercel AI SDK
@api-route/ai-sdk-provider is a minimal OpenAI-compatible community provider for the current Vercel AI SDK. It supports text generation, streaming, and tool calling in Node.js and Edge runtimes.
Setup
Install the provider and AI SDK:
npm install @api-route/ai-sdk-provider aiOpen API Access on the API Route website to get your Base URL and API key, then set:
API_ROUTE_BASE_URL="your-base-url"
API_ROUTE_API_KEY="your-api-key"The Base URL should include the API version path shown in API Access.
Quickstart
import { generateText } from 'ai';
import { apiRoute } from '@api-route/ai-sdk-provider';
const { text } = await generateText({
model: apiRoute('your-model-id'),
prompt: 'Hello!',
});
console.log(text);Any model ID string accepted by your API Route endpoint can be passed directly.
Streaming
import { streamText } from 'ai';
import { apiRoute } from '@api-route/ai-sdk-provider';
const result = streamText({
model: apiRoute('your-model-id'),
prompt: 'Write a short story.',
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}Tool calling
import { generateText, jsonSchema, tool } from 'ai';
import { apiRoute } from '@api-route/ai-sdk-provider';
const result = await generateText({
model: apiRoute('your-model-id'),
prompt: 'What is the weather in Shanghai?',
tools: {
weather: tool({
description: 'Get weather by city',
inputSchema: jsonSchema<{ city: string }>({
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
additionalProperties: false,
}),
}),
},
});
console.log(result.toolCalls);Tool support depends on the selected model.
Custom configuration
Explicit settings override environment variables. Custom headers are merged after Bearer authentication headers by the underlying OpenAI-compatible provider.
import { createAPIRoute } from '@api-route/ai-sdk-provider';
const apiRoute = createAPIRoute({
baseURL: 'https://your-base-url/v1',
apiKey: 'your-api-key',
headers: { 'X-Custom-Header': 'value' },
fetch: customFetch,
});Resources
Scope
This first release intentionally exposes only OpenAI-compatible chat language models. Image, audio, completion-only, and embedding APIs are not included.
License
Apache-2.0
