Traveler Duty of Care · 12 / 26

Development with the AI (artificial intelligence) Gateway

How an engineer builds the duty platform's documentation assistant against an enterprise AI gateway: aliases, keys, budgets, guardrails, errors and tests, with language models kept away from the alert path and exact locations.

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

td-fast and td-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.

In this platform language models are used only for documentation. They never receive exact locations or traveler names, and are never part of the path from event to alert.

The developer workflow

  1. 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. 2 · Call the sandbox

    Develop against the sandbox gateway, which runs the same scanning with small budgets and synthetic data only.

  3. 3 · Use aliases and tools

    Call td-fast for extraction and drafting, td-reasoner for hard cases. Tools are declared in the request; execution stays in your service.

  4. 4 · Handle gateway errors

    Treat a guardrail block, a budget stop and a provider failure as different outcomes with different handling.

  5. 5 · Run the evaluation set

    Run the shared evaluation set against your branch. Thresholds gate the merge.

  6. 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 drafts an incident report uses the standard OpenAI-compatible SDK (Software Development Kit) with the base URL (Uniform Resource Locator) pointed at the gateway. The service passes structured facts and metadata as headers. The result is a draft.

documentation/llm.py · a draft through the gateway
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": "duty-platform", "x-stage": "documentation"},
)

def draft_incident_report(facts: dict, incident_id: str, trace_id: str) -> str:
    resp = client.chat.completions.create(
        model="td-fast",                            # alias, repointed by the platform team
        messages=[
            {"role": "system", "content": INCIDENT_REPORT_PROMPT},
            {"role": "user", "content": json.dumps(facts)},      # structured facts only: counts and times, no names or locations
        ],
        temperature=0,
        extra_headers={"x-incident-id": incident_id, "x-trace-id": trace_id},
    )
    return resp.choices[0].message.content   # a draft: the duty officer edits and signs before anything is filed

The code never names a vendor or a model version. A repoint of the td-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. Volumes are small, so budgets are small.

gateway/duty.yaml · illustrative
routes:
  - alias: td-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: 15000
    guardrails: [ prisma-airs:duty-docs-prod ]
  - alias: td-reasoner
    primary:   { provider: provider-a, model: large-model }
    fallbacks: [ { provider: provider-b, model: large-model } ]
    timeout_ms: 45000
    guardrails: [ prisma-airs:duty-docs-prod ]

keys:
  td-platform-prod:
    routes: [ td-fast, td-reasoner ]
    budget:     { usd_per_day: 60, alert_at: 0.8 }
    rate_limit: { requests_per_minute: 60 }
    metadata_required: [ x-app, x-incident-id, x-trace-id ]

Errors and what happens to the draft

Gateway outcomeMeaningService behaviourResult for the work item
200 with contentNormal reply, scans passedContinue the pipelineNormal processing
Guardrail blockInput or output failed a scanLog a security event, do not retry the same text, never echo the blocked contentRouted to a person with the reason
429 rate or budgetKey limit reachedBack off, then queue the work and alert the platform teamDelayed, not lost
5xx or timeoutProvider failure after fallbacksKeep the state, retry once, then queue for a personDelayed or routed to a person
Schema failureModel returned an invalid structureRetry once with the validation error, then route to a personRouted to a person
A gateway call with retry and fallback The service calls the gateway with an alias. The gateway checks the key, scans the facts, tries the primary provider, retries, fails over to the second provider, scans the reply and returns the draft with usage and cost. Service AI gateway Prisma AIRS Provider A Provider B completion, alias td-fast check key, budget, rate limit scan input allow route to primary 503 retry after 250 ms retry 503 fallback route completion scan reply allow 200, usage, cost, fallback flag
A gateway call with retry and fallback

The service sees one call and one answer. Which provider answered shows only in the metadata.

Testing without surprises

  1. Unit tests

    Mock the gateway client and test the rules, validators and error handling with fixed replies.

  2. Record and replay

    Record sandbox responses for a set of cases and replay them in CI (continuous integration), so tests are fast and free.

  3. Contract tests

    Check that every alias the service uses exists, returns the structure expected and carries the required metadata.

  4. Adversarial tests

    Include prompt injection, personal-data and tool-abuse cases and assert that the gateway blocks them and the service handles the block.

  5. Cost tests

    Assert a token budget per unit of work and fail the build if a prompt change doubles it.

Developer checklist

Build this for your business

This example is speculative, but the same pattern, minimal and consented data, deterministic rules for every safety duty, a governed gateway, runtime security, advisory-only AI and accountable people, fits any service that looks after people. We can scope a pilot on your own systems.

Book a discovery call