This section documents how the gateway codebase is organized. It is written to help you find the right folder quickly and understand what each file does.
apps/api/src layout
| Folder | Purpose | Key files |
|---|
apps/api/src/routes | HTTP routing and endpoint registration. | root.ts, v1/index.ts, v1/control/health.ts, v1/control/models.ts |
apps/api/src/lib/gateway | Request pipeline, adapters, pricing, and telemetry. | pipeline.ts, execute/, before/, after/ |
apps/api/src/ir | Intermediate representation (IR) for normalized requests/responses. | types.ts, streaming.ts |
apps/api/src/protocols | Protocol-specific parsing and emitters. | openai/, anthropic/ |
apps/api/src/router | Surface selection and strictness handling. | surfaces.ts, strictness.ts, param_classifier.ts |
apps/api/src/runtime | Runtime env bindings and helpers. | env.ts |
apps/api/src/lib | Shared schemas, error handler, and utilities. | schemas.ts, types.ts, error-handler.ts |
How requests flow
- Routes register protocol-accurate endpoints under
apps/api/src/routes.
- Protocol parsers map request bodies into the IR (
apps/api/src/ir).
- The gateway pipeline selects providers and executes upstream calls.
- Responses are normalized back into IR and emitted in the original protocol shape.
Last modified on February 11, 2026