Add provider package

From vercel/ai · View interactive version

Add provider package is an AI agent skill from the GitHub repository vercel/ai. Guide for adding first-party AI provider packages to the AI SDK. Use when creating a provider package under packages/ to integrate an external AI service.

How to use this skill

Skill file

Add a Provider Package

Add a complete first-party @ai-sdk/<provider> package that follows the current provider interfaces, repository conventions, security requirements, and release process.

Read the Current Sources of Truth

Before implementing anything, read:

Use PR #18595 as a recent end-to-end example, but choose the current provider package whose API shape and model types most closely resemble the new provider as the implementation reference.

Third parties can publish provider packages outside this repository. A new first-party @ai-sdk/<provider> package requires prior discussion in an issue. Confirm that agreement exists before implementing the package.

Discover the API Contract

Before designing model classes, look for an official, versioned OpenAPI or Swagger specification in the provider's documentation or repositories. Prefer first-party specifications and record the source URL plus its version, publication date, or commit in the implementation notes or pull request.

Use the specification and official documentation to identify:

Treat an OpenAPI specification as implementation evidence, not unquestioned truth. Specifications are often incomplete for server-sent events, streaming deltas, polymorphic content, tool calls, nullable fields, and errors. Do not add a generated client or generated production types by default. Implement minimal hand-written types and Zod schemas, then verify them against official documentation and captured API responses.

If no official specification exists, derive the contract from official documentation and real response fixtures, and note that limitation in the pull request.

Plan the Provider Shape

Determine which AI SDK model interfaces the provider supports, such as LanguageModelV4, EmbeddingModelV4, ImageModelV4, SpeechModelV4, TranscriptionModelV4, RerankingModelV4, or Experimental_VideoModelV4.

Before introducing a dependency, public API pattern, or new abstraction, read contributing/decisions/README.md and relevant accepted ADRs. Prefer existing provider utilities and implementation patterns.

Scaffold the Package

Create packages/<provider>/ by adapting a current, comparable provider package. A typical package contains:

packages/<provider>/
├── src/
│   ├── index.ts
│   ├── version.ts
│   ├── <provider>-provider.ts
│   ├── <provider>-provider.test.ts
│   ├── <provider>-<model-type>-model.ts
│   ├── <provider>-<model-type>-model.test.ts
│   └── <provider>-<model-type>-options.ts
├── CHANGELOG.md
├── README.md
├── package.json
├── tsconfig.json
├── tsdown.config.ts
├── turbo.json
├── vitest.node.config.js
└── vitest.edge.config.js

Preserve current package conventions rather than recreating configuration from memory:

Implement the Provider Factory

Follow the current provider factory pattern:

Implement Model Classes

Implement each supported model using the appropriate interface from @ai-sdk/provider and shared utilities from @ai-sdk/provider-utils.

Provider option types and schemas must follow the repository naming and export rules. User-facing option fields should use .optional() unless null is meaningful. Response schemas should be minimal, tolerate unused provider fields, and use .nullish() where the API may omit or return null.

All model classes must implement the workflow serialization contract described in Provider development notes:

Handle Responses, Errors, and URLs Safely

Read Secure URL handling before implementing any polling or provider-supplied download URL flow.

Test Against the Real Contract

Add focused tests for:

Use real provider responses as fixtures when practical. Read the capture API response fixture skill before capturing them. Trim oversized fixtures only when doing so does not change their semantics.

Add Examples and Repository Integration

Read the AI Functions example skill before adding examples.

For each supported model type, put the entry example at:

examples/ai-functions/src/<function>/<provider>/basic.ts

Put additional examples in the same provider directory with descriptive kebab-case.ts names. Do not create flat provider files such as src/generate-text/<provider>.ts.

Also update the relevant repository integration points:

Run representative examples against the real API and confirm both non-streaming and streaming behavior when supported.

Add Package and Provider Documentation

Prepare the Release

Create a major changeset for the new provider package. The repository package remains at plain 2.0.0; do not add -beta, -canary, or another prerelease suffix.

Before the first automated release, coordinate with the Vercel IT team to bootstrap an empty @ai-sdk/<provider> package on npm at 0.0.0 and configure its Trusted Publisher. Follow Bootstrapping a new CODE2 package. The temporary npm bootstrap version is separate from the repository package version.

When main is in prerelease mode, do not backport the new package to a stable vX.Y branch.

Verify the Complete Change

Run, at minimum:

pnpm --filter @ai-sdk/<provider> build
pnpm --filter @ai-sdk/<provider> test
pnpm --filter @ai-sdk/<provider> type-check
pnpm type-check
pnpm check

Also run the new examples with the required provider credentials. Run the root build when changes to shared packages or build configuration make it relevant.

Completion Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.