Google Cloud API Gateway Model Routing: OpenAI-Compatible AI Traffic Without LiteLLM
> A practical guide to Google Cloud API Gateway model routing in Public Preview: OpenAI-compatible requests, Gemini and Claude backends, OpenAPI configuration, fallback risks, security, and limitations.
🎧 Listen — ~11 min
Ready · Google Cloud API Gateway Model R
Google Cloud API Gateway Model Routing: OpenAI-Compatible AI Traffic Without LiteLLM
Google Cloud API Gateway now offers model routing in Public Preview. The feature gives an application one OpenAI-compatible entry point while the gateway selects a configured Gemini, Claude, or OpenAI OSS-GPT backend from the request’s model value and translates the request in flight.
That is useful for teams that want centralized authentication, quotas, routing rules, and model endpoint changes without shipping provider-specific URLs through every client. It is not a semantic model router, automatic quality optimizer, or general-purpose replacement for an application policy engine. In the current preview, routing is deterministic string matching, and an unknown model can fall through to the configured default.
Key takeaways
- Google Cloud API Gateway model routing is a managed ingress layer, currently in Public Preview.
- Clients send OpenAI-compatible JSON; the gateway maps a model name to a configured backend.
- Routes can target Gemini, Anthropic Claude, or OpenAI GPT-family models hosted through Agent Platform Model Garden.
- Every backend in one router must use the same hostname and URL scheme.
- Routing requires OpenAPI 3.x extensions and cannot be mixed with ordinary gateway operations in one specification.
- Existing gateways cannot be toggled into or out of model-routing mode; deploy a new API config and gateway.
- The preview supports response streaming, but not request-side streaming, gRPC, WebSockets, or Gemini Live.
What Google Cloud model routing actually does
Google’s August 4 announcement describes model routing as a lightweight, serverless ingress layer for AI traffic. A client calls a stable gateway endpoint with an OpenAI-style request. API Gateway inspects the request’s model field, compares it with rules in an OpenAPI 3.x specification, transforms the payload for the selected Agent Platform model, and returns the response.
The request path is therefore:
The important boundary is the selector. The gateway does not infer that a difficult prompt needs a larger model, compare quality scores, or fail over after an upstream error. It routes based on the configured model string. Your application still owns model-selection policy, feature compatibility, retries, circuit breaking, and business-level fallback decisions.
This separation fits well with a broader agent architecture. For example, MCP’s stateless transport changes make request routing and authorization more explicit at the protocol boundary, while model routing makes the model endpoint boundary explicit at the gateway.
When the managed gateway is a good fit
Model routing is most useful when several applications currently carry their own provider configuration. A platform team can expose one controlled endpoint, keep client authentication separate from backend model credentials, and change a backend mapping centrally.
Typical use cases include:
- Providing a small approved model catalog to internal agents.
- Keeping provider credentials out of application configuration.
- Applying gateway authentication, quotas, and aggregate traffic controls.
- Moving from one hosted model to another without changing every SDK client.
- Giving teams a stable OpenAI-compatible interface while the platform team manages Google-hosted model paths.
It is less suitable when you need cross-cloud routing among arbitrary provider hosts, prompt-semantic routing, sophisticated token-cost optimization, or a mature failover layer. Google’s current design requires the backends referenced by one router to share a hostname, so it is not a universal multi-provider proxy.
Prerequisites and architectural constraints
Before writing the OpenAPI document, check these constraints from Google’s documentation.
Use separate provisioning and runtime identities
The operator or CI principal creating API configs and gateways needs the API Gateway administration permission, including roles/apigateway.admin. The service account used by the gateway needs roles/aiplatform.user to reach the target models. These should be treated as separate trust boundaries.
Use a dedicated runtime service account in production. Avoid granting a broad default identity access to every model or project resource. Record which gateway, API config, and service account correspond to each routing catalog so an audit can reconstruct the path from client request to model call.
Keep one hostname per router
All backends referenced by a router must use the same hostname and URL scheme. Google’s examples use aiplatform.googleapis.com; a regional endpoint can also be used, but do not mix a global host with a regional host in the same router. The model-specific path may differ.
Use OpenAPI 3.x only
Model routing uses Google’s OpenAPI 3.x extensions. The x-google-model-router extension belongs on a POST operation. It cannot be placed at the document root or path level, and it cannot coexist with x-google-backend on the same operation.
A specification also cannot mix model-routed and ordinary gateway operations. Keep model ingress in its own gateway specification instead of adding a conventional health or business endpoint beside it.
Plan immutable gateway changes
A gateway deployed without model routing cannot be upgraded in place to enable it, and a routing gateway cannot be converted back to ordinary routing. Create a new API config and gateway when changing modes. Treat routing specifications as versioned deployment artifacts rather than mutable settings.
A minimal OpenAPI routing specification
The following pattern is adapted from Google’s official example. Replace the project ID and model identifiers with the models available in your Agent Platform Model Garden catalog.
1openapi: 3.0.4
2info:
3 title: OpenAI-compatible model router
4 version: 1.0.0
5x-google-api-management:
6 backends:
7 gemini-default:
8 address: >-
9 https://aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash-lite:generateContent
10 deadline: 60.0
11 pathTranslation: CONSTANT_ADDRESS
12 claude-option:
13 address: >-
14 https://aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/global/publishers/anthropic/models/claude-opus-4-7:rawPredict
15 deadline: 60.0
16 pathTranslation: CONSTANT_ADDRESS
17 ai:
18 models:
19 routing:
20 routers:
21 production-router:
22 defaultModel:
23 backend: gemini-default
24 targetModel: google/gemini-3.5-flash-lite
25 rules:
26 - model: claude-opus-4-7
27 backend: claude-option
28 targetModel: anthropic/claude-opus-4-7
29servers:
30 - url: https://gateway.example.com
31paths:
32 /v1/chat/completions:
33 post:
34 operationId: createChatCompletion
35 x-google-model-router: production-router
36 responses:
37 '200':
38 description: Successful model responseThere are two names to keep distinct. backend is the local key for an address in the OpenAPI document. targetModel is the provider/model identifier Google uses when translating the request. A typo in either place can make deployment fail or send traffic somewhere unexpected, so validate the rendered specification in CI before creating the API config.
Deployment and request flow
The deployment process is intentionally versioned. Enable the required services, grant the gateway service account access to the target models, create an API config from the OpenAPI document, then create a new gateway pointing at that config. Wait for the gateway to become active before storing its final hostname.
A client request can remain simple:
1curl --fail-with-body \
2 "https://gateway.example.com/v1/chat/completions" \
3 -H "content-type: application/json" \
4 -H "x-api-key: $API_KEY" \
5 -d '{
6 "model": "claude-opus-4-7",
7 "messages": [
8 {"role": "user", "content": "Explain idempotency in one sentence."}
9 ]
10 }'The gateway intercepts the POST, reads model, selects the Claude rule, translates the OpenAI-compatible payload to the configured Agent Platform prediction format, adds backend authentication, and returns the response. The application does not need to know the provider-specific rawPredict path.
That compatibility should not be overinterpreted. OpenAI-compatible ingress does not mean that every provider supports identical tool schemas, structured-output settings, token limits, stop behavior, or streaming events. Create a contract test for every target model and keep the supported feature matrix next to the routing specification.
The dangerous default: unknown models can fall through
The preview selects defaultModel when no rule matches. This can preserve availability, but it can also hide a typo or policy error. An agent that requests claude-opus-4-7-latest instead of the configured claude-opus-4-7 may silently run on Gemini, changing cost, latency, data residency assumptions, or output behavior.
Add client-side validation before the request reaches the gateway:
1ALLOWED_MODELS = {
2 "gemini-3.5-flash-lite",
3 "claude-opus-4-7",
4}
5
6
7def validate_model(model: str) -> str:
8 if model not in ALLOWED_MODELS:
9 raise ValueError(f"Unsupported model selector: {model}")
10 return modelAlso test the negative path deliberately. Send an unknown selector in a non-production environment and verify that the observed behavior matches your risk decision. If fallback is acceptable, log the original selector and the resolved backend so operators can distinguish an intentional default from a client mistake. If fallback is not acceptable, reject unknown selectors in the application or put a policy layer in front of the gateway.
For agent workloads, pair model validation with the same bounded permissions and evidence loop used for other autonomous systems. Harness engineering for AI coding agents offers a useful pattern: define the allowed actions, run deterministic checks, capture evidence, and make failure explicit instead of letting the system improvise.
Security, observability, and cost considerations
The gateway separates client authentication from backend model authentication, which makes credential rotation easier. It does not remove the need for least privilege. Protect API keys, restrict who can edit routing specifications, and review every newly added target model as a data-flow change.
Do not assume that centralized routing automatically provides model-level cost attribution. Capture the requested model, resolved backend, tenant or application identity, request outcome, latency, and token usage where available. Correlate those records with gateway logs and provider-side telemetry. A single endpoint can simplify operations while making attribution less visible if the logging design is incomplete.
The preview has notable technical limits:
| Area | Current behavior | Engineering implication |
|---|---|---|
| Selector | Exact model name/tag matching | Keep a versioned allowlist and contract tests |
| Default | Unmatched requests use defaultModel | Guard against typos and policy bypasses |
| Backends | Same hostname and scheme per router | Not a general cross-host provider proxy |
| Specification | OpenAPI 3.x, routed operations only | Isolate model ingress from ordinary APIs |
| Streaming | Response streaming supported | Test event compatibility per provider |
| Unsupported protocols | No request-side streaming, gRPC, WebSockets, or Gemini Live | Use another path for realtime workloads |
| Network controls | VPC Service Controls and PSC unsupported | Review perimeter and endpoint requirements |
| Latency | Cold starts may occur when scaled to zero | Measure first-request and steady-state latency |
| Timeout | Gateway maximum is 3,600 seconds | Still set a smaller application budget |
Treat Public Preview as a reason to stage the service, not as a reason to skip controls. Start with a low-risk workload, version the router, test every model branch, and keep a rollback path to the previous client or gateway implementation.
A practical adoption checklist
- Define the approved model catalog and exact selector strings.
- Create a dedicated gateway runtime service account.
- Confirm every backend shares the intended host and HTTPS scheme.
- Render and lint the OpenAPI 3.x document in CI.
- Deploy a new API config and gateway; do not mutate an incompatible gateway.
- Test explicit rules, the default path, malformed payloads, auth failures, and provider-specific response shapes.
- Record requested model, resolved backend, latency, status, and usage signals.
- Add client-side rejection for unknown selectors if silent fallback is unsafe.
- Load-test cold starts, streaming, timeouts, and concurrency before production traffic.
- Review the preview limitations again before expanding to agents or regulated data.
If your clients already use a common OpenAI SDK, the stable endpoint can reduce migration work. If your problem is deeper—semantic routing, cross-cloud failover, advanced spend optimization, or policy based on user and prompt context—keep the gateway as one layer and add the policy engine explicitly rather than expecting the preview to provide it.
FAQ
Is Google Cloud API Gateway model routing a replacement for LiteLLM?
It can replace a small amount of self-managed routing and endpoint translation for supported Google-hosted models. It is not feature-equivalent to every open-source gateway and does not provide arbitrary cross-host routing or all-purpose fallback behavior.
Does it choose a model based on prompt meaning?
No. The preview matches the request’s model value against configured rules. Your application or agent must decide which selector to send.
Can one router target Gemini and Claude?
Yes, when the referenced backends use the same hostname and scheme and the models are available through the supported Agent Platform Model Garden path.
Can I add normal API operations to the same OpenAPI file?
No. Google documents that a specification cannot mix model-routing and non-model-routing operations. Use separate gateway specifications.
Is it ready for realtime voice or bidirectional agent sessions?
Not based on the documented preview capabilities. Request-side streaming, gRPC, WebSockets, and Gemini Live are unsupported. Use a transport designed for those workloads.
Conclusion
Google Cloud API Gateway model routing is a pragmatic control point for teams that want a stable OpenAI-compatible endpoint without operating another proxy. Its strongest value is operational: central routing rules, separated credentials, and a managed deployment boundary.
Its limitations are equally important. Routing is string-based, unmatched requests use a default, one router is constrained to a shared host, and the preview does not cover realtime protocols. Deploy it as a narrow, versioned model-ingress layer, validate selectors before sending them, and instrument the resolved route. That approach gets the portability benefit without turning a convenient default into an invisible production policy.
Sources and visual credit
- Google Developers Blog: Model routing with Google Cloud API Gateway
- Google Cloud documentation: Overview of model routing
- Google Cloud documentation: Configure model routing
- The Syntax Diaries: Google Cloud API Gateway Model Routing in Production
The architecture diagram is original Mermaid markup created for this article; no external image assets are used.
Visual: Model execution pipeline
This original flow explains the runtime path behind the model or agent discussed here. It separates context preparation, inference, tools, and output verification.
Visual reading: the model is one stage in the system, not the whole system. Tool calls and generated artifacts need an explicit verification boundary before they are trusted.
| Stage | Main question | Useful signal |
|---|---|---|
| Context | Is the input relevant and complete? | Grounding and prompt size |
| Inference | Is the model meeting the task? | Quality, latency, token use |
| Tools | Are actions permitted? | Success and permission errors |
| Output | Can the result be used safely? | Tests, review, provenance |
Keep reading
Related reading
⚡ Daily AI Model Drop — Get Kimi K3 benchmarks before Twitter
Join 2,400+ AI engineers. 1 email/day, no spam, unsubscribe anytime