By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
The first production mistake is letting each feature call the provider SDK directly. It works for one endpoint, then the second endpoint invents its own timeout, the third forgets the request ID, and the fourth leaks a provider stack trace to a customer. A gateway fixes this by making one function the only place a model is called. Everything upstream sees a stable contract; everything downstream is swappable.
For Waypoint the gateway owns four things: the typed request and response, the request ID, the wall-clock deadline and the structured error. The provider adapter is an implementation detail behind it. Swapping a hosted model for the deterministic simulator should change nothing above the gateway.
The example below is FastAPI-style but deliberately plain: a Pydantic request model, a response model, a provider stand-in and a handler function. Because the provider is deterministic, the printed values are expected, not captured from a live model. The validation branch is the point of the typed edge: a malformed exception is rejected before it can cost a token.
import json
import uuid
from pydantic import BaseModel, Field, ValidationError
class AssistRequest(BaseModel):
exception_id: str = Field(pattern=r"^EXC-\d{4}$")
tenant_id: str = Field(min_length=2)
message: str = Field(min_length=1, max_length=2000)
class AssistResponse(BaseModel):
request_id: str
status: str
draft: str
model_id: str
class FakeProvider:
model_id = "waypoint-sim-1"
def complete(self, prompt: str) -> dict:
return {
"text": "Northline clause 4.2 supports a delay credit; customer update drafted."
}
def request_id_for(tenant_id: str, exception_id: str) -> str:
# Production uses UUIDv4 or a ULID. uuid5 keeps this example reproducible.
name = f"{tenant_id}:{exception_id}"
return "req_" + uuid.uuid5(uuid.NAMESPACE_URL, name).hex[:12]
def assist(req: AssistRequest) -> AssistResponse:
reply = FakeProvider().complete(req.message)
return AssistResponse(
request_id=request_id_for(req.tenant_id, req.exception_id),
status="ok",
draft=reply["text"],
model_id=FakeProvider.model_id,
)
response = assist(
AssistRequest(
exception_id="EXC-4821",
tenant_id="northline",
message="Draft the customer update for the delayed load.",
)
)
print(json.dumps(response.model_dump(exclude={"request_id"}), indent=2))
print("request id prefix ok:", response.request_id.startswith("req_"))
try:
AssistRequest(exception_id="4821", tenant_id="northline", message="hi")
except ValidationError as exc:
print("rejected at the edge:", exc.errors()[0]["type"])A gateway is also an error translator. The caller should never receive a raw provider exception, because that leaks vendor details and gives the client nothing actionable. Define a small error schema once and map every failure into it.
| Status | When Waypoint returns it | Client-visible body |
|---|---|---|
| 400 | The request body is malformed or fails schema validation | {error: {code, message, request_id}} |
| 404 | The exception or shipment does not exist for this tenant | {error: {code, message, request_id}} |
| 409 | The requested action needs approval first | {error: {code: approval_required, request_id, approval_id}} |
| 429 | The tenant is over its rate or spend limit | {error: {code: rate_limited, retry_after_ms}} plus Retry-After |
| 503 | The provider is unavailable and no fallback succeeded | {error: {code: provider_unavailable, retryable: true}} |
| 504 | The gateway deadline expired before a usable result | {error: {code: deadline_exceeded, retryable: true}} |
The request ID is assigned exactly once, at admission, and it travels everywhere: the gateway log line, every model span, every tool call, the approval record and the response header. When a customer asks why a refund went out twice, the request ID is the difference between a five-minute answer and an afternoon of log archaeology.
Key takeaways
One gateway function owns every model call: typed contract, request ID, deadline, structured errors.
The provider adapter sits behind the gateway, so a real model and the deterministic simulator are interchangeable.
Translate provider failures into a small error schema; never leak raw vendor errors.
Assign the request ID at admission and carry it through logs, spans, tool calls and the response.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.