Skip to main content

AI Gateway

Route agent model calls through the AI Gateway with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for the workload.

Observability

Export the traces and logs Workers emit to Orq.ai over OpenTelemetry, straight from the Workers runtime.

AI Gateway

Overview

Cloudflare Agents run on Workers and Durable Objects, and call models through the AI SDK. Pointing that provider at Orq.ai’s AI Gateway sends every model call that uses it through the gateway, so routing, fallbacks, and cost tracking apply to those calls. Calls that read the Workers AI binding directly keep going to Cloudflare.

Key Benefits

Connecting Cloudflare Agents to Orq.ai’s AI Gateway adds:

Complete Observability

Track model calls and their token usage 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 every AI operation

Multi-Provider Access

Access 500+ LLMs and 30+ providers through a single, unified integration

Prerequisites

Before integrating Cloudflare Agents with Orq.ai, confirm:
  • An Orq.ai account and API Key
  • A Cloudflare account with a Worker created from the Cloudflare Agents starter
  • wrangler installed and authenticated

Installation

Install the Agents SDK and the AI SDK with the OpenAI-compatible provider:
Store the Orq.ai API key as a Worker secret:

Configure the Gateway

Create the provider once and pass it the gateway base URL. this.env carries the secret stored above:
TypeScript
baseURL: https://my.orq.ai/v3/router

Basic Agent Example

Every model call in an Agent subclass goes through the gateway with that provider:
TypeScript
For a streaming chat agent, the starter’s AIChatAgent takes the same provider in onChatMessage:
TypeScript

Model Selection

With Orq.ai, use any supported model from 30+ providers by changing the model id:
TypeScript
See Supported Models for the catalog.

Observability

Getting Started

Cloudflare exports Workers telemetry to any OpenTelemetry-compliant destination, and Orq.ai is one of them, so traces and logs arrive from the Workers runtime itself.

Create the destination

Cloudflare keeps destinations at the account level, so the same destination serves every Worker in the account.
  1. In the Cloudflare dashboard, open Observability > Destinations and select Add destination.
  2. Name the destination, for example orq-traces, and set Destination type to Traces.
  3. Set OTLP endpoint to https://my.orq.ai/v2/otel/v1/traces.
  4. Add an Authorization entry under Custom headers with the value Bearer <ORQ_API_KEY>.
  5. Save, then repeat with the name orq-logs, the type Logs, and the endpoint https://my.orq.ai/v2/otel/v1/logs.
Both destinations use the same header, and the exporter accepts the base path or the full path. See the Observability quickstart for the general OTLP contract and Base URLs for self-hosted deployments.

Reference the destination in Wrangler

Name the destinations in the Worker configuration, then redeploy:
wrangler.jsonc
  • Sample rate: head_sampling_rate is the share of requests exported, from 0 to 1. Lower it on high-volume Workers.
  • Persist: persist keeps a copy in Cloudflare as well. Persisted traces and logs count toward Cloudflare Observability usage from 1 December 2026, so the value above exports to Orq.ai alone.
Events can take several minutes to reach the destination after the first deploy.

View Traces

Open Traces for the path each request takes through the Worker and its connected services, and Logs for the console.log output the Worker emits. Model calls are recorded by the gateway, so they appear in the trace of the request that made them.

Traces

See each request through the Worker and the services it calls.

Logs

Search the console.log output a Worker emits during a run.

Evaluations & Experiments

Once agents are running, use Evaluatorq to score outputs across a dataset and Experiments to compare configurations side-by-side.

Run Evaluations with Evaluatorq

Run parallel evaluations across a set of agents and compare results.

Run Experiments via the API

Compare agent configurations and view results in the AI Studio.