Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.
The Vercel AI SDK provides a simple and unified API for interacting with OpenAI-compatible language models. This guide explains how to integrate the SDK with OpenAI or any OpenAI-compatible API endpoint for text generation, streaming, image generation, and multimodal (vision) capabilities.
Prerequisites
Before you begin, ensure you have:
Node.js 18+
An OpenAI-compatible API endpoint
An API key
npm or another package manager
Installation
Install the required packages:
npm install ai @ai-sdk/openai dotenv
Package Overview
Package
Description
ai
Core Vercel AI SDK containing text generation, streaming, and image APIs.
@ai-sdk/openai
OpenAI provider that supports both OpenAI and OpenAI-compatible endpoints.
dotenv
Loads API keys and configuration from environment variables.
Reuse a single OpenAI client instance throughout your application.
Use streaming for chat interfaces to improve user experience.
Validate generation parameters before making requests.
Handle API errors gracefully with retry or fallback logic.
Use system prompts to define consistent assistant behavior.
Keep prompts concise and specific for better model responses.
Supported Features
Feature
Supported
Text Generation
✅
Streaming Responses
✅
System Prompts
✅
Temperature
✅
Top P
✅
Top K
✅
Max Tokens
✅
Frequency Penalty
✅
Presence Penalty
✅
Seed
✅
Stop Sequences
✅
Image Generation
✅
Vision (Image Input)
✅
OpenAI-Compatible Base URL
✅
Next Steps
You are now ready to build applications using the Vercel AI SDK with any OpenAI-compatible endpoint. Explore additional SDK capabilities such as structured outputs, tool calling, agents, and chat history management as your application grows.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"ZnapAI Documentation","colors":{"primary":"#0070F3","light":"#F5F5F5","dark":"#020817"},"logo":{"light":"https://mintcdn.com/znapai/X7VdddzKw4eGXooz/logo/znapai_logo.png?fit=max\u0026auto=format\u0026n=X7VdddzKw4eGXooz\u0026q=85\u0026s=39865a595b1244cfa16411d8b03bebd4","dark":"https://mintcdn.com/znapai/X7VdddzKw4eGXooz/logo/znapai_logo.png?fit=max\u0026auto=format\u0026n=X7VdddzKw4eGXooz\u0026q=85\u0026s=39865a595b1244cfa16411d8b03bebd4"},"favicon":"https://mintcdn.com/znapai/bfneBgsrIC5SHCWi/favicon.svg?fit=max\u0026auto=format\u0026n=bfneBgsrIC5SHCWi\u0026q=85\u0026s=65f7ca5a5e7986acb06e088184e0ae67","navbar":{"links":[{"href":"https://znapai.com/models","label":"Models"}],"primary":{"type":"button","label":"Dashboard","href":"https://znapai.com/app"}},"footer":{"socials":{}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","grok"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"znapai","hasAudioNarration":false,"actualSubdomain":"znapai","customDomains":["docs.znapai.com"],"gitSource":{"type":"github","owner":"amzamani","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"entitlements":{},"buildId":"6acf3625f69ce708bc03e854","clientVersion":"0.0.4142","searchFilterCounts":[{"language":"default","tag":"Docs","count":12},{"language":"default","tag":"Core concepts","count":11},{"language":"default","tag":"Integrations","count":9},{"language":"default","tag":"OpenAI","count":8},{"language":"default","tag":"AI SDK","count":4},{"language":"default","tag":"Anthropic","count":2},{"language":"default","tag":"Usage","count":1},{"language":"default","tag":"Models","count":1}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"integrations/vercel-ai-sdk","slug":"/integrations/vercel-ai-sdk","pageMetadata":{"title":"Vercel AI SDK","description":"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.","href":"/integrations/vercel-ai-sdk"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,hr:`hr`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,Table}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The `,_jsx(_components.strong,{children:`Vercel AI SDK`}),` provides a simple and unified API for interacting with OpenAI-compatible language models. This guide explains how to integrate the SDK with OpenAI or any OpenAI-compatible API endpoint for text generation, streaming, image generation, and multimodal (vision) capabilities.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`prerequisites`,children:`Prerequisites`}),`\n`,_jsx(_components.p,{children:`Before you begin, ensure you have:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Node.js 18+`}),`\n`,_jsx(_components.li,{children:`An OpenAI-compatible API endpoint`}),`\n`,_jsx(_components.li,{children:`An API key`}),`\n`,_jsx(_components.li,{children:`npm or another package manager`}),`\n`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`installation`,children:`Installation`}),`\n`,_jsx(_components.p,{children:`Install the required packages:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`npm`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` install`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ai`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` @ai-sdk/openai`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` dotenv`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`package-overview`,children:`Package Overview`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Package`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ai`})}),_jsx(_components.td,{children:`Core Vercel AI SDK containing text generation, streaming, and image APIs.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`@ai-sdk/openai`})}),_jsx(_components.td,{children:`OpenAI provider that supports both OpenAI and OpenAI-compatible endpoints.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`dotenv`})}),_jsx(_components.td,{children:`Loads API keys and configuration from environment variables.`})]})]})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`environment-variables`,children:`Environment Variables`}),`\n`,_jsxs(_components.p,{children:[`Create a `,_jsx(_components.code,{children:`.env`}),` file:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`5`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`API_KEY=your_api_key`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`BASE_URL=https://your-openai-compatible-endpoint/v1`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`MODEL_NAME=gpt-4o-mini`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`IMAGE_MODEL_NAME=gpt-image-2`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`BASE_URL`}),` is optional when using the official OpenAI API. Specify it only when connecting to an OpenAI-compatible provider or proxy.`]})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`client-configuration`,children:`Client Configuration`}),`\n`,_jsx(_components.p,{children:`Create a reusable client configuration.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`16`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`16`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`createOpenAI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@ai-sdk/openai'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` *`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` dotenv`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'dotenv'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`dotenv`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`config`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` apiKey`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` process`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` baseURL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` process`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`BASE_URL`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` process`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`MODEL_NAME`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` IMAGE_MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` process`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`IMAGE_MODEL_NAME`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` createOpenAI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` apiKey`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` baseURL`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`]})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`next-steps`,children:`Next Steps`}),`\n`,_jsx(_components.p,{children:`To explore individual capabilities with code examples, check the following sections in the sidebar:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/integrations/vercel-ai-sdk-text`,children:`Text Generation`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/integrations/vercel-ai-sdk-image`,children:`Image Generation`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/integrations/vercel-ai-sdk-vision`,children:`Image to Text (Vision)`})}),`\n`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`best-practices`,children:`Best Practices`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Store API keys in environment variables.`}),`\n`,_jsx(_components.li,{children:`Reuse a single OpenAI client instance throughout your application.`}),`\n`,_jsx(_components.li,{children:`Use streaming for chat interfaces to improve user experience.`}),`\n`,_jsx(_components.li,{children:`Validate generation parameters before making requests.`}),`\n`,_jsx(_components.li,{children:`Handle API errors gracefully with retry or fallback logic.`}),`\n`,_jsx(_components.li,{children:`Use system prompts to define consistent assistant behavior.`}),`\n`,_jsx(_components.li,{children:`Keep prompts concise and specific for better model responses.`}),`\n`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`supported-features`,children:`Supported Features`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Feature`}),_jsx(_components.th,{children:`Supported`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Text Generation`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Streaming Responses`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`System Prompts`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Temperature`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Top P`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Top K`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Tokens`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Frequency Penalty`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Presence Penalty`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Seed`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Stop Sequences`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Image Generation`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Vision (Image Input)`}),_jsx(_components.td,{children:`✅`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`OpenAI-Compatible Base URL`}),_jsx(_components.td,{children:`✅`})]})]})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`next-steps-2`,children:`Next Steps`}),`\n`,_jsx(_components.p,{children:`You are now ready to build applications using the Vercel AI SDK with any OpenAI-compatible endpoint. Explore additional SDK capabilities such as structured outputs, tool calling, agents, and chat history management as your application grows.`})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Vercel AI SDK","description":"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.","href":"/integrations/vercel-ai-sdk"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Prerequisites","slug":"prerequisites","depth":2,"children":[]},{"title":"Installation","slug":"installation","depth":2,"children":[{"title":"Package Overview","slug":"package-overview","depth":3,"children":[]}]},{"title":"Environment Variables","slug":"environment-variables","depth":2,"children":[]},{"title":"Client Configuration","slug":"client-configuration","depth":2,"children":[]},{"title":"Next Steps","slug":"next-steps","depth":2,"children":[]},{"title":"Best Practices","slug":"best-practices","depth":2,"children":[]},{"title":"Supported Features","slug":"supported-features","depth":2,"children":[]},{"title":"Next Steps","slug":"next-steps-2","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"znapai","siteName":"ZnapAI Documentation","title":"Vercel AI SDK - ZnapAI Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-06-28T08:45:55.960Z","originalFileLocation":"integrations/vercel-ai-sdk.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.\">\u003cmeta data-mint-head name=\"application-name\" content=\"ZnapAI Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Vercel AI SDK - ZnapAI Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"ZnapAI Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.znapai.com/integrations/vercel-ai-sdk\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://znapai.mintlify.site/_mintlify/api/og/v2?division=Documentation\u0026amp;title=Vercel+AI+SDK\u0026amp;description=Learn+how+to+integrate+the+Vercel+AI+SDK+with+OpenAI-compatible+language+models.\u0026amp;theme=e067a142740eb1672409cc87\u0026amp;signature=4de48b47d4d71b2bb85707c53835c356d24a8d949afd285c39165e78d8dc2942\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Vercel AI SDK - ZnapAI Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://znapai.mintlify.site/_mintlify/api/og/v2?division=Documentation\u0026amp;title=Vercel+AI+SDK\u0026amp;description=Learn+how+to+integrate+the+Vercel+AI+SDK+with+OpenAI-compatible+language+models.\u0026amp;theme=e067a142740eb1672409cc87\u0026amp;signature=4de48b47d4d71b2bb85707c53835c356d24a8d949afd285c39165e78d8dc2942\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/znapai/qH6ePpRr7iu8fkmy/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"ZnapAI Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#0070F3\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.znapai.com/integrations/vercel-ai-sdk\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/integrations/vercel-ai-sdk.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.znapai.com/#organization\",\"name\":\"ZnapAI Documentation\",\"url\":\"https://docs.znapai.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/znapai/X7VdddzKw4eGXooz/logo/znapai_logo.png?fit=max\u0026auto=format\u0026n=X7VdddzKw4eGXooz\u0026q=85\u0026s=39865a595b1244cfa16411d8b03bebd4\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.znapai.com#website\",\"name\":\"ZnapAI Documentation\",\"url\":\"https://docs.znapai.com\",\"publisher\":{\"@id\":\"https://docs.znapai.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.znapai.com/integrations/vercel-ai-sdk#webpage\",\"url\":\"https://docs.znapai.com/integrations/vercel-ai-sdk\",\"name\":\"Vercel AI SDK\",\"description\":\"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.\",\"dateModified\":\"2026-06-28T08:45:55.960Z\",\"isPartOf\":{\"@id\":\"https://docs.znapai.com#website\"}},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.znapai.com/integrations/vercel-ai-sdk#article\",\"headline\":\"Vercel AI SDK\",\"name\":\"Vercel AI SDK\",\"description\":\"Learn how to integrate the Vercel AI SDK with OpenAI-compatible language models.\",\"url\":\"https://docs.znapai.com/integrations/vercel-ai-sdk\",\"mainEntityOfPage\":{\"@id\":\"https://docs.znapai.com/integrations/vercel-ai-sdk#webpage\"},\"dateModified\":\"2026-06-28T08:45:55.960Z\",\"publisher\":{\"@id\":\"https://docs.znapai.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.znapai.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"ZnapAI Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"ZnapAI Documentation\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/integrations/vercel-ai-sdk.md","siteName":"ZnapAI Documentation","nav":{"global":null,"tabs":[{"tab":"Docs","pages":[{"title":"Docs","href":"/introduction"}]},{"tab":"OpenAI","pages":[{"title":"OpenAI","href":"/openai-intro"}]},{"tab":"Anthropic","pages":[{"title":"Anthropic","href":"/anthropic-intro"}]},{"tab":"AI SDK","pages":[{"title":"Vercel AI SDK","href":"/integrations/vercel-ai-sdk"},{"group":"Core concepts","pages":[{"title":"Text Generation","description":"Learn how to use the Vercel AI SDK for text generation, streaming responses, and handling parameters or errors.","href":"/integrations/vercel-ai-sdk-text"},{"title":"Image Generation","href":"/integrations/vercel-ai-sdk-image"},{"title":"Image to Text","href":"/integrations/vercel-ai-sdk-vision"}]}]}]},"basePath":"","title":"Vercel AI SDK - ZnapAI Documentation","buildId":"dpl_G2Qd45vZZ7MkBiGF9yYx8ZsbbKXX","deploymentId":"dpl_G2Qd45vZZ7MkBiGF9yYx8ZsbbKXX","dynamics":[],"chunks":[]}