Vercel AI SDK
The AI SDK is a TypeScript toolkit for building AI features and agents. Bayle connects through
the @ai-sdk/openai-compatible provider.
Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/sdks/vercel-ai-sdk/
Goal: use Bayle models in my Vercel AI SDK (https://ai-sdk.dev) code through the OpenAI-compatible provider.
1. Install the packages if they are missing from my project:
npm install ai @ai-sdk/openai-compatible
2. Pick a model:
curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'
Show me the list, let me choose, and use that id as MODEL_ID.
3. In my code, create the provider like this:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { generateText } from 'ai'
const bayle = createOpenAICompatible({
name: 'bayle',
baseURL: 'https://api.bayle.ai',
apiKey: process.env.BAYLE_API_KEY,
})
const { text } = await generateText({
model: bayle('MODEL_ID'),
prompt: 'In one sentence, what is an embedding?',
})
console.log(text)
streamText, tools and structured output work the same way with bayle('MODEL_ID'). Do not use @ai-sdk/openai's default model function: since AI SDK 5, openai('id') calls OpenAI's Responses API, which Bayle does not serve. If my code already uses createOpenAI({ baseURL }), call openai.chat('MODEL_ID') instead.
4. Verify by running that snippet and show me the output.
Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.Install
Section titled “Install”npm install ai @ai-sdk/openai-compatibleSee the official OpenAI-compatible provider guide for the other package managers.
Don't have a Bayle key yet?Get API key
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'import { generateText } from 'ai'
const bayle = createOpenAICompatible({ name: 'bayle', baseURL: 'https://api.bayle.ai', apiKey: process.env.BAYLE_API_KEY,})
const { text } = await generateText({ model: bayle('MODEL_ID'), prompt: 'In one sentence, what is an embedding?',})console.log(text)streamText, tools and structured output work the same way with bayle('MODEL_ID').
Pick a model
Section titled “Pick a model”curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'