Skip to main content
Mastra is a TypeScript framework for building AI agents, tools, and workflows. Connect it to Venice by configuring a custom OpenAI-compatible model endpoint.

Prerequisites

Create a Mastra project

Add your Venice API key to the generated project’s .env file:
Keep .env out of source control. Do not expose your Venice API key in browser-side code.

Create a Venice-powered agent

Create an agent and point its model configuration at the Venice API:
The first segment of id is Mastra’s routing label. Mastra sends the remaining model ID, venice-uncensored, to Venice.
Set url to the base API URL shown above. Do not append /chat/completions; Mastra adds that path.
Register the agent in your Mastra instance:
Start the development server and open the URL shown in your terminal to test the agent in Mastra Studio:

Generate a response

Retrieve the registered agent and call generate():

Stream a response

Use stream() when you want to display output as it arrives:

Add tools

Mastra tools use Zod schemas to validate their inputs and outputs. Use a Venice model that supports function calling when attaching tools to an agent.
Attach the tool to an agent:

Generate structured output

Pass a Zod schema through structuredOutput to receive validated data:
If the selected model does not support the API’s structured-output mode, set jsonPromptInjection: true inside structuredOutput to have Mastra add the schema to the prompt instead.

Change models

To use another Venice text model, keep the venice/ routing prefix and replace the remaining model ID:
Browse available Venice models and check their capabilities before selecting one for tool calling, vision, or structured output.

Troubleshooting

Confirm that VENICE_API_KEY is present in the environment where Mastra runs, then restart the development server after changing .env.
Use the exact model ID shown on the models page. In Mastra, prefix it with venice/, for example venice/venice-uncensored.
Set the model URL to https://api.venice.ai/api/v1. Do not use the full /chat/completions endpoint.
Choose a model that supports function calling, describe when the agent should use the tool in its instructions, and define the tool with createTool().

Mastra Documentation

Learn more about Mastra agents, tools, and workflows

Venice Models

Browse models and supported capabilities