Compatible Gateways

Cloudflare AI Gateway

Use Cloudflare AI Gateway's OpenAI-compatible endpoint with Anvia.

Cloudflare AI Gateway provides an OpenAI-compatible chat completions endpoint under https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat.

Create the Client

import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";

const accountId = process.env.CLOUDFLARE_ACCOUNT_ID;
const gatewayId = process.env.CLOUDFLARE_AI_GATEWAY_ID ?? "default";

const client = new OpenAIClient({
  baseUrl: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/compat`,
  apiKey: process.env.CLOUDFLARE_AI_GATEWAY_API_KEY,
});

const model = client.completionModel("anthropic/claude-sonnet-4.5");

const agent = new AgentBuilder("support", model)
  .instructions("Answer support questions clearly.")
  .build();

const response = await agent.prompt("Hello!").send();

console.log(response.output);

Use Cloudflare's gateway model format, usually provider/model.

Get the Model List

If your Cloudflare AI Gateway configuration exposes the OpenAI-compatible models endpoint, listModels() reads it through the configured baseUrl.

const models = await client.listModels();

console.table(models.data.map((model) => ({ id: model.id, owner: model.ownedBy })));

Notes

  • Cloudflare supports provider-native routes and an OpenAI-compatible unified route. This page uses the OpenAI-compatible route.
  • Authentication depends on whether you use unified billing, stored keys, or request headers in Cloudflare.
  • Model availability and feature support depend on the selected upstream provider.

For current Cloudflare AI Gateway details, see the getting started guide and OpenAI-compatible endpoint documentation.