Skip to content

About

Vercel AI SDK community provider for API Route, an OpenAI-compatible multi-model AI gateway.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

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 ai

Open 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

About

Vercel AI SDK community provider for API Route, an OpenAI-compatible multi-model AI gateway.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages