What the gateway gives a developer
The enterprise AI gateway is the one front door to models. A developer does not hold a provider key, pick a vendor or write retry logic. They call an OpenAI-compatible endpoint with a project key and a model alias, and the platform team owns routing, fallback, budgets, guardrails and logging behind it. The gateway in this example sits in front of Prisma AIRS scanning; the same developer experience applies whichever product provides the gateway, such as Portkey or the Databricks AI Gateway.
Header names, paths and configuration keys below are illustrative. Use the names your gateway documents.
Model aliases
ly-fast and ly-reasoner, never a vendor model name. The platform team repoints an alias after the evaluation set passes.
Project keys
One key per service and environment, with its own budget and rate limit. Keys are issued and rotated by the platform team.
Default guardrails
The security profile attached to the key scans every request. Developers do not call the scanner themselves.
Metadata
Each call carries an application name, case identifier and trace identifier, so cost and incidents can be traced to a unit of work.
The developer workflow
1 · Request a project
Raise a request with the service name, data classes and expected volume. The platform team creates the dev, test and prod keys, budgets and a security profile.
2 · Call the sandbox
Develop against the sandbox gateway, which runs the same scanning with small budgets and synthetic data only.
3 · Use aliases and tools
Call ly-fast for extraction and drafting, ly-reasoner for hard cases. Tools are declared in the request; execution stays in your service.
4 · Handle gateway errors
Treat a guardrail block, a budget stop and a provider failure as different outcomes with different handling.
5 · Run the evaluation set
Run the shared evaluation set against your branch. Thresholds gate the merge.
6 · Promote
The prod key is bound to the production profile. Nothing in the code changes between environments except configuration.
Calling the gateway
A step that reads a boarding pass uses the standard OpenAI-compatible SDK (Software Development Kit) with the base URL (Uniform Resource Locator) pointed at the gateway. The service passes metadata as headers and asks for a structured result.
import os, json
from openai import OpenAI
client = OpenAI(
base_url=os.environ["AI_GATEWAY_URL"], # the gateway, not a provider
api_key=os.environ["AI_GATEWAY_KEY"], # project key with a budget
default_headers={"x-app": "loyalty-platform", "x-stage": "claims"},
)
def extract_boarding_pass(text: str, case_id: str, trace_id: str) -> dict:
resp = client.chat.completions.create(
model="ly-fast", # alias, repointed by the platform team
messages=[
{"role": "system", "content": BOARDING_PASS_PROMPT},
{"role": "user", "content": text}, # text extracted from the image, already scanned
],
response_format={"type": "json_schema", "json_schema": BOARDING_PASS_SCHEMA},
temperature=0,
extra_headers={"x-case-id": case_id, "x-trace-id": trace_id},
)
return json.loads(resp.choices[0].message.content)The code never names a vendor or a model version. A repoint of the ly-fast alias is a configuration change, tested by the evaluation set first.
Gateway configuration as code
The platform team keeps routes, budgets and guardrail attachments in version control and reviews changes like any other code. Award sales raise the daily budget by a planned change, not by hand.
routes:
- alias: ly-fast
primary: { provider: provider-a, model: small-model }
fallbacks: [ { provider: provider-b, model: small-model } ]
retries: { attempts: 2, on: [429, 500, 503], backoff_ms: 250 }
timeout_ms: 10000
guardrails: [ prisma-airs:loyalty-documents-prod ]
- alias: ly-reasoner
primary: { provider: provider-a, model: large-model }
fallbacks: [ { provider: provider-b, model: large-model } ]
timeout_ms: 45000
guardrails: [ prisma-airs:loyalty-documents-prod ]
keys:
ly-platform-prod:
routes: [ ly-fast, ly-reasoner ]
budget: { usd_per_day: 2000, alert_at: 0.8 }
rate_limit: { requests_per_minute: 1500 }
metadata_required: [ x-app, x-case-id, x-trace-id ]Errors and what happens to the item
| Gateway outcome | Meaning | Service behaviour | Result for the work item |
|---|---|---|---|
| 200 with content | Normal reply, scans passed | Continue the pipeline | Normal processing |
| Guardrail block | Input or output failed a scan | Log a security event, do not retry the same text, never echo the blocked content | Routed to a person with the reason |
| 429 rate or budget | Key limit reached | Back off, then queue the work and alert the platform team | Delayed, not lost |
| 5xx or timeout | Provider failure after fallbacks | Keep the state, retry once, then queue for a person | Delayed or routed to a person |
| Schema failure | Model returned an invalid structure | Retry once with the validation error, then route to a person | Routed to a person |
The service sees one call and one answer. Which provider answered shows only in the metadata.
The two errors need different handling, which is why the error table separates them.
Testing without surprises
Unit tests
Mock the gateway client and test the rules, validators and error handling with fixed replies.
Record and replay
Record sandbox responses for a set of cases and replay them in CI (continuous integration), so tests are fast and free.
Contract tests
Check that every alias the service uses exists, returns the structure expected and carries the required metadata.
Adversarial tests
Include prompt injection, personal-data and tool-abuse cases and assert that the gateway blocks them and the service handles the block.
Cost tests
Assert a token budget per unit of work and fail the build if a prompt change doubles it.
Developer checklist
- No provider keys, vendor SDKs or model version names in the repository.
- Every call carries application, case and trace metadata.
- Guardrail blocks, rate limits and provider failures each have a tested path.
- Structured outputs are validated against a schema in code.
- Prompts and aliases are versioned, and changes run the evaluation set.
- No personal data in prompts that the task does not need.
Build this for your business
This example is a loyalty platform for an airline, but the same pattern, deterministic financial rules, a governed gateway, runtime security, consent-aware personalisation and measured quality, fits any program that holds a customer balance and makes offers. We can scope a pilot on your own systems.
Book a discovery call