Skip to lesson
Exit
Routing, failover and backpressure1 / 2

1 min lesson

Design one provider-neutral gateway

Design a gateway contract that separates shared policy from provider-specific wire details.

Step 1 of 2

Cursor's current job description says every agent session, Tab completion and chat message flows through the Model Routing and Inference team's stack. One example project is a single abstraction over every provider's API so onboarding a model becomes a configuration change.

Providers differ in authentication, request fields, response fields, streaming events and error meanings. The gateway translates those differences so callers can use one model interface.

Use a small adapter for each provider's wire format. Keep shared behavior such as timeouts, retry budgets, tracing, token accounting and idempotency in the gateway core. Make the shared request capability-aware. A caller should state whether it needs tools, images, structured output or a particular context size. Routing can then reject an incompatible model before sending work. Run the same contract fixtures against every adapter and verify request mapping, stream events, error categories and usage records.

Learn more

Full explanation

See the gateway layers

Gateway responsibilities from caller to provider

Interactive diagram. Tab through its regions; each focused region shows its detail in the panel below.

diagram: stack

Callers use one contract. Each adapter handles the details of one provider API.