---
title: "Mastra with EU-hosted models · Agent setup guide"
description: "Point Mastra agents and workflows at inference.eu with a custom model URL and run them on open-weight models processed in EU data centres."
canonical: "https://inference.eu/integrations/mastra/"
language: "en"
---

Frameworks · Mastra

# Use Mastra with open-source models hosted in the EU

Mastra is a TypeScript framework for building AI agents, workflows and RAG pipelines. Its model router accepts any OpenAI-compatible endpoint through a \`url\` setting, so your agents can run on open-weight models at inference.eu, processed in European data centres.

[Contact sales](https://inference.eu/contact/)[Setup](#setup)

1.  01API format: OpenAI
2.  02EU data centres
3.  03Covered by one DPA

## Set it up in a few minutes

1.  1

    Create an API key in your inference.eu account and add `INFERENCE_EU_API_KEY` to your project's `.env` file.

2.  2

    In your agent definition, set `model` to an object with `id`, `url` and `apiKey` instead of a model string.

3.  3

    Use `inference-eu/` followed by the model id as `id`, the inference.eu base URL as `url` and `process.env.INFERENCE_EU_API_KEY` as `apiKey`.

4.  4

    Register the agent in your `Mastra` instance as usual.

5.  5

    Start `mastra dev` and send the agent a message in Studio to confirm the connection.

src/mastra/agents/support-agent.ts

```
import { Agent } from "@mastra/core/agent";

export const supportAgent = new Agent({
  id: "support-agent",
  name: "Support agent",
  instructions: "You answer customer questions using the tools provided.",
  model: {
    id: "inference-eu/kimi-k3",
    url: "https://api.inference.eu/v1",
    apiKey: process.env.INFERENCE_EU_API_KEY,
  },
});
```

## What Mastra is

Mastra is an open-source TypeScript framework from the team behind Gatsby. It provides agents with tools and memory, graph-based workflows with suspend and resume, RAG helpers, evaluations and a local Studio for testing. Mastra apps run in Node.js and deploy to servers, serverless platforms or inside existing web frameworks.

Models are chosen through Mastra's model router. Besides the built-in providers, it accepts a custom OpenAI-compatible endpoint by passing `url` alongside the model id, which is the documented way to connect a service such as inference.eu.

## How the configuration works

Instead of a string like `"openai/..."`, set `model` to an object. `id` uses the form `provider/model`; with `inference-eu/kimi-k3`, Mastra sends the bare model id `kimi-k3` to the endpoint. `url` is the inference.eu base URL ending in `/v1`, never the full chat completions path. `apiKey` is sent as a bearer token.

Custom URLs use the Chat Completions API by default, which is what you want for inference.eu. If you prefer, you can also create a provider with `createOpenAICompatible` from the AI SDK and pass the resulting model to the agent; Mastra accepts AI SDK models directly.

## Which models to choose

Mastra agents call tools and often run inside multi-step workflows, so models with dependable tool calling work best. `kimi-k3` and `glm-5.3` are strong defaults for support, research and operations agents that plan and use several tools.

For agents that write or review code, use `qwen3-coder-480b-a35b-instruct`. For quick classification, routing or structured extraction steps inside a workflow, `gpt-oss-120b` keeps latency low. Each agent and workflow step can use its own model object, and Mastra's model fallbacks let you list a second inference.eu model to try if the first fails.

## Troubleshooting

A 401 error means `INFERENCE_EU_API_KEY` is not set where the agent runs; check the `.env` file locally and the environment settings of your deployment. A 404 usually means `url` includes `/chat/completions` or another extra path. Use the base URL ending in `/v1`.

"Model not found" means the part of `id` after `inference-eu/` does not match an inference.eu model id. If structured output fails, simplify the Zod schema. If an agent ignores its tools, choose a model with stronger tool calling. Do not set `api: "responses"` for inference.eu; keep the default Chat Completions path.

## Keeping data in the EU

With the model pointed at inference.eu, the messages, memory excerpts and tool results your agents send are processed in EU data centres and never used for training. We sign a data processing agreement under Article 28 GDPR, publish our subprocessor list and bill in euros.

Mastra itself only calls the services you configure. Memory storage, vector databases and observability exporters each hold data too, so choose EU-hosted or self-hosted options for them. Deploy your Mastra server in an EU region so that requests are not handled elsewhere before they reach inference.eu.

## Mastra

Category

Frameworks

Maker

Mastra

API format

OpenAI

Processing

EU data centres

Website

[mastra.ai](https://mastra.ai/)

Documentation

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

## Mastra: common questions

The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.

Set the agent's \`model\` to an object with \`id\`, \`url\` and \`apiKey\`. \`url\` is the endpoint's base URL ending in \`/v1\`, and \`id\` uses the form \`provider/model\`. Mastra then sends requests to that endpoint through its model router.

Use \`inference-eu/\` followed by the inference.eu model id, for example \`inference-eu/kimi-k3\`. Mastra treats the first part as the provider name and sends the bare model id, \`kimi-k3\`, to the endpoint.

Kimi K3 and GLM-5.3 are strong defaults for agents that plan and call several tools. Qwen3 Coder 480B suits coding agents, and gpt-oss-120b is a quick choice for classification and routing steps in workflows.

The \`url\` must be the base URL, not an individual endpoint. Remove \`/chat/completions\` or any other path so that it ends in \`/v1\`; Mastra appends the endpoint path itself. Then check that the model id is correct.

Yes. Mastra accepts AI SDK models directly, so you can create a provider with \`createOpenAICompatible\` pointing at inference.eu and pass \`inferenceEu("kimi-k3")\` as the agent's model. Both approaches send the same requests.

Yes. Workflow steps that call agents use whichever model each agent is configured with. You can give each agent its own inference.eu model, using a fast one for routing steps and a stronger one for reasoning-heavy steps.

Yes. Pass a Zod schema as the structured output option when you call the agent and Mastra validates the result. Keep schemas simple and test them with your chosen model, since adherence varies between models.

Yes. Mastra lets an agent list several models to try in order. Use two inference.eu models, for example Kimi K3 followed by GLM-5.3, so that a failed request is retried on another model without leaving the EU.

Memory is stored in the storage adapter you configure, such as PostgreSQL or LibSQL. Host that database in the EU, and choose an EU-hosted embedder if you use semantic recall, so that stored conversations stay in Europe.

The deployment does not have \`INFERENCE\_EU\_API\_KEY\`. Add the variable in your hosting platform's environment settings, redeploy, and confirm the agent reads it with \`process.env.INFERENCE\_EU\_API\_KEY\` rather than a hard-coded value in the source.

[Ask a question](https://inference.eu/contact/)

## Related

[All integrations](https://inference.eu/integrations/)

-   [Vercel AI SDKUse the Vercel AI SDK's OpenAI-compatible provider to call open-weight models processed in EU data centres from Next.js, Node.js or edge apps.SDKs](https://inference.eu/integrations/vercel-ai-sdk/)
-   [OpenAI SDK (Python and JavaScript)Point the official OpenAI Python or JavaScript SDK at inference.eu with base\_url and an API key, and call open-weight models processed in the EU.SDKs](https://inference.eu/integrations/openai-sdk/)
-   [Pydantic AIConnect Pydantic AI agents to inference.eu with OpenAICompatibleProvider and get typed, validated output from open-weight models processed in the EU.Frameworks](https://inference.eu/integrations/pydantic-ai/)

## Move your AI workloads to EU infrastructure

Tell us which models you use and roughly how much traffic you have. We reply within one working day with pricing and next steps.

-   Reply within one working day
-   Pricing for your volume
-   DPA ready to sign
