
Add Provider Package
OfficialFreeIntegrate new AI services into the AI SDK effortlessly.
Free · Opens the source repo
What Add Provider Package does
The Add Provider Package skill is designed to assist developers in creating new @ai-sdk/<provider> packages for integrating AI services into the AI SDK. This skill provides a comprehensive guide that outlines the necessary steps to establish a structured package that adheres to the SDK's architecture. The process is straightforward, enabling developers to focus on implementing their AI service without getting bogged down by configuration details.
The skill covers the creation of package structures, configuration of package.json, TypeScript setups, and the implementation of provider-specific logic. It emphasizes the use of a layered provider architecture, which follows the adapter pattern, ensuring that new providers can be integrated seamlessly into the existing SDK framework. This architecture includes specifications, utilities, and core functionalities, allowing for a modular approach to adding new capabilities.
By following the step-by-step guide provided, developers can create both first-party and third-party packages, ensuring they meet the necessary requirements for integration. The skill also includes examples and best practices for writing tests, creating README documentation, and implementing model classes, which are essential for maintaining code quality and usability. This makes the Add Provider Package skill particularly valuable for developers looking to expand the functionality of the AI SDK with new AI services.
Overall, this skill is aimed at developers who are familiar with TypeScript and the AI SDK, and who are looking to enhance their projects by adding new AI service providers. It streamlines the integration process, making it easier to contribute to the growing ecosystem of AI services.
When to use it
Use this skill when you need to create a new provider package to add an AI service to the AI SDK.
When not to use it
This skill is not suitable for users unfamiliar with TypeScript or those not working with the AI SDK.
What you can build with it
Integrating a New AI Service
When you want to add a new AI service to your application, this skill guides you through the package creation process.
Creating a Third-Party Provider
If you are developing a third-party AI service, this skill provides the necessary steps to package and integrate it.
Maintaining SDK Compatibility
Use this skill to ensure that your new provider packages adhere to the AI SDK's architecture and standards.
How to install Add Provider Package
View source1. Install with the skills CLI
npx skills add vercel/ai/add-provider-package --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by vercelAdding a New Provider Package
This guide covers the process of creating a new @ai-sdk/<provider> package to integrate an AI service into the AI SDK.
First-Party vs Third-Party Providers
- Third-party packages: Any provider can create a third-party package. We're happy to link to it from our documentation.
- First-party
@ai-sdk/<provider>packages: If you prefer a first-party package, please create an issue first to discuss.
Reference Example
See https://github.com/vercel/ai/pull/8136/files for a complete example of adding a new provider.
Provider Architecture
The AI SDK uses a layered provider architecture following the adapter pattern:
- Specifications (
@ai-sdk/provider): Defines interfaces likeLanguageModelV4,EmbeddingModelV4, etc. - Utilities (
@ai-sdk/provider-utils): Shared code for implementing providers - Providers (
@ai-sdk/<provider>): Concrete implementations for each AI service - Core (
ai): High-level functions likegenerateText,streamText,generateObject
Step-by-Step Guide
1. Create Package Structure
Create a new folder packages/<provider> with the following structure:
packages/<provider>/
├── src/
│ ├── index.ts # Main exports
│ ├── version.ts # Package version
│ ├── <provider>-provider.ts # Provider implementation
│ ├── <provider>-provider.test.ts
│ ├── <provider>-*-options.ts # Model-specific options
│ └── <provider>-*-model.ts # Model implementations (e.g., language, embedding, image)
├── package.json
├── tsconfig.json
├── tsconfig.build.json
├── tsup.config.ts
├── turbo.json
├── vitest.node.config.js
├── vitest.edge.config.js
└── README.md
Do not create a CHANGELOG.md file. It will be auto-generated.
2. Configure package.json
Set up your package.json with:
"name": "@ai-sdk/<provider>""version": "0.0.0"(initial version, will be updated by changeset)"type": "module""license": "Apache-2.0""sideEffects": false- Dependencies on
@ai-sdk/providerand@ai-sdk/provider-utils(useworkspace:*) - Dev dependencies:
@ai-sdk/test-server,@types/node,@vercel/ai-tsconfig,tsup,typescript,zod "engines": { "node": ">=22" }- Peer dependency on
zod(both v3 and v4):"zod": "^3.25.76 || ^4.1.8"
Example package entry point configuration:
{
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
}
}
3. Create TypeScript Configurations
tsconfig.json:
{
"extends": "@vercel/ai-tsconfig/base.json",
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
tsconfig.build.json:
{
"extends": "./tsconfig.json",
"exclude": [
"**/*.test.ts",
"**/*.test-d.ts",
"**/__snapshots__",
"**/__fixtures__"
]
}
4. Configure Build Tool (tsup)
Create tsup.config.ts:
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
sourcemap: true,
clean: true,
});
5. Configure Test Runners
Create both vitest.node.config.js and vitest.edge.config.js (copy from existing provider like anthropic).
6. Implement Provider
Provider implementation pattern:
// <provider>-provider.ts
import { NoSuchModelError } from '@ai-sdk/provider';
import { loadApiKey } from '@ai-sdk/provider-utils';
export interface ProviderSettings {
apiKey?: string;
baseURL?: string;
// provider-specific settings
}
export class ProviderInstance {
readonly apiKey?: string;
readonly baseURL?: string;
constructor(options: ProviderSettings = {}) {
this.apiKey = options.apiKey;
this.baseURL = options.baseURL;
}
private get baseConfig() {
return {
apiKey: () =>
loadApiKey({
apiKey: this.apiKey,
environmentVariableName: 'PROVIDER_API_KEY',
description: 'Provider API key',
}),
baseURL: this.baseURL ?? 'https://api.provider.com',
};
}
languageModel(modelId: string) {
return new ProviderLanguageModel(modelId, this.baseConfig);
}
// Shorter alias
chat(modelId: string) {
return this.languageModel(modelId);
}
}
// Export default instance
export const providerName = new ProviderInstance();
7. Implement Model Classes
Each model type (language, embedding, image, etc.) should implement the appropriate interface from @ai-sdk/provider:
LanguageModelV4for text generation modelsEmbeddingModelV4for embedding modelsImageModelV4for image generation models- etc.
Schema guidelines:
Provider Options (user-facing):
- Use
.optional()unlessnullis meaningful - Be as restrictive as possible for future flexibility
Response Schemas (API responses):
- Use
.nullish()instead of.optional() - Keep minimal - only include properties you need
- Allow flexibility for provider API changes
8. Create README.md
Include:
- Brief description linking to documentation
- Installation instructions
- Basic usage example
- Link to full documentation
9. Write Tests
- Unit tests for provider logic
- API response parsing tests using fixtures in
__fixtures__subdirectory - Both Node.js and Edge runtime tests
See capture-api-response-test-fixture skill for capturing real API responses for testing.
10. Add Examples
Create examples in examples/ai-functions/src/ for each model type the provider supports:
generate-text/<provider>.ts- Basic text generationstream-text/<provider>.ts- Streaming textgenerate-object/<provider>.ts- Structured output (if supported)stream-object/<provider>.ts- Streaming structured output (if supported)embed/<provider>.ts- Embeddings (if supported)generate-image/<provider>.ts- Image generation (if supported)- etc.
Add feature-specific examples as needed (e.g., <provider>-tool-call.ts, <provider>-cache-control.ts).
11. Add Documentation
Create documentation in content/providers/01-ai-sdk-providers/<last number + 10>-<provider>.mdx
Include:
- Setup instructions
- Available models
- Model capabilities
- Provider-specific options
- Usage examples
- API configuration
12. Create Changeset
Run pnpm changeset and:
- Select the new provider package
- Choose
majorversion (for new packages starting at 0.0.0) - Describe what the package provides
13. Update References
Run pnpm update-references from the workspace root to update tsconfig references.
14. Build and Test
# From workspace root
pnpm build
# From provider package
cd packages/<provider>
pnpm test # Run all tests
pnpm test:node # Run Node.js tests
pnpm test:edge # Run Edge tests
pnpm type-check # Type checking
# From workspace root
pnpm type-check:full # Full type check including examples
15. Run Examples
Test your examples:
cd examples/ai-functions
pnpm tsx src/generate-text/<provider>.ts
pnpm tsx src/stream-text/<provider>.ts
Provider Method Naming
- Full names:
languageModel(id),imageModel(id),embeddingModel(id)(required) - Short aliases:
.chat(id),.image(id),.embedding(id)(for DX)
File Naming Conventions
- Source files:
kebab-case.ts - Test files:
kebab-case.test.ts - Type test files:
kebab-case.test-d.ts - Provider classes:
<Provider>Provider,<Provider>LanguageModel, etc.
Security Best Practices
- Never use
JSON.parsedirectly - useparseJSONorsafeParseJSONfrom@ai-sdk/provider-utils - Load API keys securely using
loadApiKeyfrom@ai-sdk/provider-utils - Validate all API responses against schemas
Error Handling
Errors should extend AISDKError from @ai-sdk/provider and use a marker pattern:
import { AISDKError } from '@ai-sdk/provider';
const name = 'AI_ProviderError';
const marker = `vercel.ai.error.${name}`;
const symbol = Symbol.for(marker);
export class ProviderError extends AISDKError {
private readonly [symbol] = true;
constructor({ message, cause }: { message: string; cause?: unknown }) {
super({ name, message, cause });
}
static isInstance(error: unknown): error is ProviderError {
return AISDKError.hasMarker(error, marker);
}
}
Pre-release Mode
If main is set up to publish beta releases, no further action is necessary. Just make sure not to backport it to the vX.Y stable branch since it will result in an npm version conflict once we exit pre-release mode on main.
Checklist
- Package structure created in
packages/<provider> -
package.jsonconfigured with correct dependencies - TypeScript configs set up (
tsconfig.json,tsconfig.build.json) - Build configuration (
tsup.config.ts) - Test configurations (
vitest.node.config.js,vitest.edge.config.js) - Provider implementation complete
- Model classes implement appropriate interfaces
- Unit tests written and passing
- API response test fixtures captured
- Examples created in
examples/ai-functions/src/ - Documentation added in
content/providers/01-ai-sdk-providers/ - README.md written
- Major changeset created
-
pnpm update-referencesrun - All tests passing (
pnpm testfrom package) - Type checking passing (
pnpm type-check:fullfrom root) - Examples run successfully
Common Issues
- Missing tsconfig references: Run
pnpm update-referencesfrom workspace root - Type errors in examples: Run
pnpm type-check:fullto catch issues early - Test failures: Ensure both Node and Edge tests pass
- Build errors: Check that
tsup.config.tsis configured correctly
Related Documentation
Frequently asked questions about Add Provider Package
Similar skills
WinMD API Search
Easily find and explore Windows desktop APIs.
WebMCPify
Transform any web app into an agent-ready platform.
Phoenix Tracing
Instrument LLM applications with OpenInference tracing.
Foundry Hosted Agent CopilotKit
Guidance for developing agentic web apps on Azure.
Power Automate Foundation
Connect AI agents to Power Automate seamlessly.
Power Automate Flow Builder
Efficiently build and deploy Power Automate flows programmatically.
