LLM Gateway & OpenRouter Integration
Relevant source files
The following files were used as context for generating this wiki page:
Speakeasy integrates with OpenRouter to provide a unified LLM gateway for the AI control plane. This integration enables the platform to support a wide range of popular AI providers—including Claude, ChatGPT, Gemini, and others—through a single connection layer. The gateway manages Large Language Model (LLM) usage across an organization, providing fine-grained permissions, threat detection, and observability for token use and associated costs.
Sources: README.md:1-20, CLAUDE.md:120-125
Architecture and Provider Support
The integration provides a single control layer that connects agents to Model Context Protocol (MCP) servers, SaaS vendors, and internal systems. It utilizes OpenRouter as the primary gateway for LLM chat interactions, requiring an OPENROUTER_DEV_KEY for local development and testing.
Supported Providers
The platform supports major AI providers through the gateway:
| Provider | Purpose |
|---|---|
| Claude / Claude Code | Advanced reasoning and coding assistance. |
| OpenAI / ChatGPT | General purpose LLM interactions. |
| Gemini | Google's multimodal LLM support. |
| GitHub Copilot / Cursor | Integrated development environment (IDE) AI support. |
Sources: README.md:22-38, CLAUDE.md:120-125
Gateway Data Flow
The following diagram represents the high-level flow of an LLM request through the Speakeasy control plane to OpenRouter.
The Speakeasy control plane acts as a secure intermediary, inspecting prompts and responses in real time before routing them to LLM providers via OpenRouter.
Sources: README.md:40-55, REVIEW.md:25-35
Local Development and Configuration
Local development of LLM-integrated features, such as Assistants and Functions, relies on the ./zero setup script. This script handles the configuration of local provider settings and build processes for the runtime environments.
Environment Configuration
To enable LLM chat locally, you must configure specific environment variables in mise.local.toml.
| Variable | Description | Default/Value |
|---|---|---|
OPENROUTER_DEV_KEY | API key required for LLM chat functionality. | User-provided |
GRAM_ASSISTANT_RUNTIME_PROVIDER | Defines the runtime provider for assistants. | local |
GRAM_CODE_RUNTIME_PROVIDER | Defines the runtime for Code Mode. | local |
Sources: CLAUDE.md:110-125, CONTRIBUTING.md:100-115
Development Procedures
- Initialize Environment: Run
./zero --agentto install dependencies, generate keys, and start Docker infrastructure. - Configure OpenRouter: Use
mise run zero:openrouterto set theOPENROUTER_DEV_KEY. - Build Runtimes:
mise run zero:assistantsbuilds the local assistant runtime image (gram-assistant-runtime:dev). - Start Stack: Run
mise run startormise run waketo activate the server, worker, and LLM gateway daemons.
Sources: CLAUDE.md:10-25, CLAUDE.md:110-120
Observability and Security
The gateway provides deep visibility into LLM interactions and enforces real-time security policies.
Security Features
- Prompt Inspection: Every prompt and response is inspected before leaving the environment.
- Sensitive Data Handling: The gateway blocks, redacts, or logs PII, secrets, and other sensitive data.
- Threat Detection: Real-time enforcement prevents prompt injection and shadow AI use.
Observability Metrics
The integration tracks usage across teams, measuring impact through:
- Token Use: Quantitative measurement of LLM consumption.
- Cost Telemetry: Financial tracking of AI expenditure.
- Audit Logging: Every tool call and permission change is logged and searchable.
Sources: README.md:40-60, REVIEW.md:110-120
Assistant Personalities and Prompting
The integration supports distinct "personalities" that define how the LLM interacts with users within the Speakeasy environment. These are defined in personalities.ts and provide structured instructions for the LLM gateway.
The platform uses these definitions to calibrate tone, voice, and formatting (such as emoji usage and capitalization) for integrated agents.
Sources: client/dashboard/src/pages/assistants/onboarding/personalities.ts:1-20
Summary
The LLM Gateway and OpenRouter integration provides a secure, observable, and multi-provider interface for AI agents within the Speakeasy platform. By centralizing LLM access, the system allows organizations to enforce security policies and track costs while leveraging the capabilities of various advanced language models.