Source: https://ailoot.ai/docs/integrations/mastra/
Canonical: https://ailoot.ai/docs/en/integrations/mastra/
Language: en

[SDKs and frameworks](https://ailoot.ai/docs/en/integrations/#sdk) 

# Mastra

[Markdown](https://ailoot.ai/docs/en/integrations/mastra/index.md)

Agent framework · OpenAI Chat, OpenAI Responses

| Format | Where to set it up |
| --- | --- |
| OpenAI Chat, OpenAI Responses | In Agent: model: { id: "\<provider\>/\<model\>", url: "\<baseURL\>", apiKey, api?: "chat" \| "responses" } |

## [](https://ailoot.ai/docs/integrations/mastra/#setup)Setup

Copy the configuration and replace `sk-...` with your key from the Ailoot Dashboard. Prefer storing the key in the environment variable `AILOOT_API_KEY`, if the application supports it.

Before starting, request GET /v1/models with your Ailoot key. Choose an exact model ID whose methods include POST /v1/chat/completions, POST /v1/responses, then use that ID in the configuration. For agents, also check tool support and the features required by your client version.

```js
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
  id: "ailoot-agent",
  name: "Ailoot Agent",
  instructions: "Respond in Russian",
  model: {
    id: "ailoot/claude-sonnet-5-5",
    url: "https://api.ailoot.ai/v1",
    apiKey: process.env.AILOOT_API_KEY
    // api: "responses"  // only for models with the responses method
  }
});
```

This configuration reads the key from the environment variable `AILOOT_API_KEY`. Set it before starting the application:

```bash
export AILOOT_API_KEY="sk-..."   # add to ~/.zshrc or ~/.bashrc
```

```powershell
setx AILOOT_API_KEY "sk-..."   # then restart the terminal
```

Example model: `ailoot/claude-sonnet-5-5, ailoot/gpt-6.1-sol`. Choose any other model from the [catalog](https://ailoot.ai/models/en/) — check that it supports the format you need.

## [](https://ailoot.ai/docs/integrations/mastra/#notes)Good to know

Set url to the base URL with /v1, not the full /chat/completions path. Chat Completions is the default; api: "responses" switches to the Responses API. The id form "provider/model" sends the bare model ID to the gateway. The documentation shows apiKey in the model object in an example with headers; its use alongside url is not described separately.

## [](https://ailoot.ai/docs/integrations/mastra/#check)Test

- For the OpenAI format, the URL is `https://api.ailoot.ai/v1` (or the full path if the application asks for a full URL).
- Ask a short question. If you get an error, check the code and Request ID, then consult [Errors and limits](https://ailoot.ai/docs/en/errors/).
- 404 immediately after setup almost always means the URL is wrong: an extra or missing `/v1`.
- 402 — insufficient balance for the reserve. Agents reserve more than chat: [why](https://ailoot.ai/docs/en/billing/reserve/).

Application documentation: [https://mastra.ai/models](https://mastra.ai/models)

Still have questions? Send your Request ID and a description — we'll help you troubleshoot.[Contact support](mailto:support@ailoot.ai)

## Ailoot · The company and its project portfolio





Ailoot combines established operating experience, a large client base, stable service and ongoing KPI control.





The company and its project portfolio: millions of customers; monthly sales in the billions.





Ailoot brings that operating experience to API access for AI features in customer products, agents, applications and automations.
