Skip to main content

Custom Providers

The AI SDK supports creating custom providers that implement the provider specification. This allows you to integrate any AI service or model with the unified AI SDK interface.

Provider Architecture

The AI SDK uses a layered provider architecture:
  1. Provider Specification (@ai-sdk/provider): Defines interfaces like LanguageModelV3
  2. Provider Utilities (@ai-sdk/provider-utils): Shared utilities for implementing providers
  3. Provider Implementation: Your custom provider that implements the specification
  4. Core Functions: generateText, streamText, etc. that work with any provider

Creating a Language Model Provider

Basic Provider Structure

A provider implements the ProviderV3 interface:

Implementing LanguageModelV3

Implement the LanguageModelV3 interface:

Using Provider Utilities

API Key Loading

URL Handling

JSON Parsing

Using Custom Providers

With Core Functions

With Middleware

In Provider Registry

Best Practices

Provider Options

Use .optional() for user-facing settings:
Use .nullish() for API response schemas:

Error Handling

Fetch Middleware

Testing Custom Providers

Next Steps