Skip to main content

AI Gateway

Overview

Mastra is a TypeScript framework for building AI-powered applications with pipelines, agents, and workflows. Connecting Mastra to Orq.ai’s AI Gateway transforms experimental AI applications into production-ready systems with enterprise-grade capabilities.

Key Benefits

Orq.ai’s AI Gateway enhances Mastra applications with:

Complete Observability

Track every agent step, tool use, and interaction with detailed traces and analytics

Built-in Reliability

Automatic fallbacks, retries, and load balancing for production resilience

Cost Optimization

Real-time cost tracking and spend management across all AI operations

Multi-Provider Access

Access 300+ LLMs and 20+ providers through a single, unified integration

Prerequisites

Before integrating Mastra with Orq.ai, ensure the following are in place:
  • An Orq.ai account and API Key
  • Node.js 18 or higher
  • TypeScript support
  • Mastra installed
To set up an API key, see API keys & Endpoints.

Installation

Install Mastra:

Configuration

Configure Mastra to use Orq.ai’s AI Gateway with an OpenAI-compatible model configuration:
TypeScript
url: https://api.orq.ai/v3/router

Basic Agent Example

Here’s a complete example of creating and running a Mastra agent through Orq.ai:
TypeScript

Model Selection

With Orq.ai, any supported model from 20+ providers can be used:
TypeScript

Agent with tools

Define tools with createTool and attach them to an agent through the tools field:
TypeScript