Skip to main content

Architecture overview

The gateway sits between your application and AI providers, adding observability, reliability, and cost controls without modifying the underlying API contract.

Workspace

A Workspace is the top-level isolated environment in MetrixLLM. Everything belongs to a workspace — there is no cross-workspace data sharing. Each workspace contains its own:
  • API keys
  • Provider credentials (BYOK)
  • Routing rules and model configurations
  • Guardrails and budget limits
  • Request logs and analytics
  • Team members and roles
  • Billing and credit balance
A typical organization structure:
Workspaces map to deployment environments. Data isolation ensures a developer viewing Development logs never sees Production user prompts.

API Key

A MetrixLLM API key (mtx_...) authenticates requests to the gateway. Keys are scoped to a single workspace and are never shared across environments. Unlike provider API keys (like OpenAI’s sk-...), MetrixLLM keys do not directly call any AI provider — they authenticate you to the gateway, which then uses your workspace’s stored provider credentials.

Key lifecycle

  1. Create — Generate a key in Settings → API Keys
  2. Use — Pass as Authorization: Bearer mtx_... header
  3. Rotate — Revoke old keys and create new ones periodically
  4. Revoke — Immediately invalidate compromised keys
API keys are hashed before storage. The full key is only shown once at creation time.

Provider & BYOK

MetrixLLM uses a Bring Your Own Key (BYOK) model. You configure your own API keys for OpenAI, Anthropic, Google, and other providers in your workspace settings. MetrixLLM stores them encrypted and uses them when routing requests on your behalf.

Supported providers

MetrixLLM does not mark up the cost of model calls. You pay your provider directly at their standard rates.

Route

A Route is a named gateway endpoint path (e.g. /v1/chat/completions). You can configure routing rules, retry logic, rate limits, and model fallback chains per route.

Default route

Every workspace starts with a “Default Route” that handles all /v1/* requests. You can create additional routes to segment traffic by use case:

Routing Rule

A Routing Rule defines how requests for a given route are handled. It contains:
  • Ordered model list — The fallback chain (first model tried, then fallbacks)
  • Retry configuration — Max retries, backoff timing, status codes to retry on
  • Rate limits — Per-route request throttling
  • Budget caps — Per-request and monthly cost limits
  • Load balancer config — Round-robin, weighted, or random across multiple targets

Fallback chain example

If OpenAI returns a 5xx or times out, the gateway automatically retries with Anthropic, then Google.

Request ID

Every request gets a unique ID in the format req_xxxxxxxx. It appears in the X-Request-Id response header and in your Request Logs. Use it to correlate a specific call across your application logs and MetrixLLM’s logs.

Session

A Session is a group of related requests tagged with the same metrix-session-id header. Use sessions to correlate multi-turn conversations or multi-step agent workflows in the Request Logs.
Sessions appear as a collapsible group in the Request Logs, making it easy to trace an entire conversation.

Cache

The Semantic Cache stores LLM responses and serves them for future requests that are identical or semantically similar. It is enabled per-workspace in settings.

How it works

  1. A request arrives at the gateway
  2. The cache checks for a semantically similar previous request
  3. If found, the cached response is returned immediately (zero latency, zero cost)
  4. If not found, the request proceeds to the provider and the response is cached

When to use caching

  • Good for: Repeated similar queries, FAQ-style responses, template-based outputs
  • Not ideal for: Highly dynamic content, real-time data, personalization-heavy prompts
Smart caching requires Pro plan or higher. Enable it in Workspace Settings → Smart Caching.

Guardrails

Guardrails are rules that validate and filter both inputs and outputs of LLM requests. They run at the gateway level before the request reaches the provider and after the response returns.

Types of guardrails

Guardrails require Pro plan or higher.

Evaluations

Evaluations measure how well your prompts and models perform against test datasets. Run evaluations in the dashboard to compare model outputs, measure quality scores, and track improvements over time. Requires Pro plan or higher.

Custom Properties

Attach arbitrary metadata to requests using the metrix-properties header. Custom properties appear in your Request Logs and can be used for filtering and analysis.

Tier & Plan

Every workspace is assigned a tier that controls feature access and usage limits: See Billing for the full feature comparison.

Durable Objects (Edge)

MetrixLLM’s Cloudflare Worker edge network uses Durable Objects to store per-workspace state (API keys, balance, configuration) at the edge. This enables:
  • Sub-millisecond key validation at the edge
  • Local rate limiting without round-trips to the origin
  • Budget enforcement even if the origin is temporarily unreachable
Durable Objects sync with the backend via NATS and internal API calls. You don’t interact with them directly — they’re an internal implementation detail.

NATS

NATS is the message bus used for real-time configuration propagation between the backend and edge gateway. When you update workspace settings (API keys, routing rules, cache toggle), the change propagates via NATS subjects:
If NATS is unavailable, the gateway falls back to database polling with a short delay.

Best practices

  • Start with Free — Prototype and validate your integration before committing to a paid plan.
  • Use sessions for multi-turn conversations — they make debugging much easier.
  • Enable caching for repetitive workloads — it can reduce costs by 30-60%.
  • Set budget alerts before going live — avoid surprise bills from runaway scripts.
  • Use custom properties to tag requests by user, feature, or environment — essential for cost attribution.
  • Rotate API keys periodically — revoke unused keys in Settings → API Keys.

Common pitfalls

Free tier is BYOK only. You must configure your own provider API keys. Pro+ supports native billing with no markup.
  • Workspace data is fully isolated. You cannot share API keys, logs, or configurations across workspaces.
  • Cache invalidation is not instant. If you change a prompt, cached responses from the old version may still be served briefly.
  • Sessions require the metrix-session-id header. Without it, multi-turn conversations appear as separate requests in logs.
  • Request IDs are per-gateway-call, not per-provider-call. If a fallback triggers, the same request ID appears in both the failed and successful log entries.