@ai-sdk/openai
OpenAI provider for the Vercel AI SDK, exposing chat, completion, embedding, and image models with typed config.
Official Documentation ↗v4.0.108. Check the official docs for the latest API surface.Installation
npm install @ai-sdk/openaiMethods
No methods match this filter.
@ai-sdk/openai is openai provider for the vercel ai sdk, exposing chat, completion, embedding, and image models with typed config. This page documents the core methods, installation, and common usage patterns for the current stable release.
Installation
Install @ai-sdk/openai with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.
Core methods
The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v1.2 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.
Frequently asked questions
The faq section in the frontmatter answers the most common questions about @ai-sdk/openai, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.
API reference evidence
Fetched from official sources on 2026-11-08T19:29:00+08:00 via WebFetch https://cdn.jsdelivr.net/npm/@ai-sdk/[email protected]/dist/index.d.ts(返回 provider V4 规格声明,与页面标注的 v4.0.108 不符);WebFetch https://unpkg.com/@ai-sdk/[email protected]/dist/index.d.ts(同上);WebFetch https://cdn.jsdelivr.net/npm/@ai-sdk/openai@1/dist/index.d.ts(provider V1 规格,LanguageModelV1/EmbeddingModelV1,与 AI SDK v4 对应).
createOpenAI→ signature from https://cdn.jsdelivr.net/npm/@ai-sdk/openai@1/dist/index.d.ts; official text: “/** Create an OpenAI provider instance. */ declare function createOpenAI(options?: OpenAIProviderSettings): OpenAIProvider;”openai.chat→ signature from https://cdn.jsdelivr.net/npm/@ai-sdk/openai@1/dist/index.d.ts; official text: “/** Creates an OpenAI chat model for text generation. */ chat(modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): LanguageModelV1;”openai.embedding→ signature from https://cdn.jsdelivr.net/npm/@ai-sdk/openai@1/dist/index.d.ts; official text: “/** Creates a model for text embeddings. */ embedding(modelId: OpenAIEmbeddingModelId, settings?: OpenAIEmbeddingSettings): EmbeddingModelV1;”
FAQ
- Does it support Azure OpenAI?
- Use @ai-sdk/azure or set baseURL and headers on createOpenAI for Azure-compatible endpoints.
- Can I use structured outputs?
- Yes. Pass the model to generateObject with a Zod schema; the provider uses JSON mode.
- Are tool calls supported?
- Yes. Define tools with zod schemas; the SDK handles multi-step tool loops.
Report a problem with this API docOpens a pre-filled issue on GitHub.