Skip to content
Try chatGet API key

Mastra

Mastra is a TypeScript framework for building agents and workflows. Its model router takes a custom OpenAI-compatible endpoint directly, with no extra provider package.

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/mastra/

Goal: run my Mastra (https://mastra.ai) agents on a Bayle model through the model router.

1. Install the core package if @mastra/core is not in my project's dependencies:
   npm install @mastra/core
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 agent definition, set the model like this. `id` is provider/model: the part before the slash is only a label, and Mastra sends the part after it as the model id. `url` is the base URL, not the full endpoint. Do not set `api: 'responses'`; a custom url uses chat completions, which is what Bayle serves:
   import { Agent } from '@mastra/core/agent'

   const agent = new Agent({
     id: 'assistant',
     name: 'Assistant',
     instructions: 'You are a concise assistant.',
     model: {
       id: 'bayle/MODEL_ID',
       url: 'https://api.bayle.ai',
       apiKey: process.env.BAYLE_API_KEY,
     },
   })
   If I already have agents, change only their `model` field.
4. Verify by running:
   const result = await agent.generate('In one sentence, what is an embedding?')
   console.log(result.text)
   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.
Terminal window
npm install @mastra/core

See the official docs for setting up a project.

Don't have a Bayle key yet?Get API key
import { Agent } from '@mastra/core/agent'
const agent = new Agent({
id: 'assistant',
name: 'Assistant',
instructions: 'You are a concise assistant.',
model: {
id: 'bayle/MODEL_ID',
url: 'https://api.bayle.ai',
apiKey: process.env.BAYLE_API_KEY,
},
})
const result = await agent.generate('In one sentence, what is an embedding?')
console.log(result.text)
  • id is provider/model. The part before the slash is a label of your choosing; Mastra sends only the part after it as the model id.
  • url is the base URL, not the full endpoint.
  • A custom url uses chat completions by default, which is what Bayle serves. Don’t set api: 'responses'.
Terminal window
curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'