Generating a Typed Client
Generate TypeScript types and a fully typed API client straight from the Outpost OpenAPI document.
The Outpost API is described by an OpenAPI 3.1 document, generated from the same route schemas the server enforces at runtime. That means you never have to hand-write request or response types: generate them from the spec and they are correct by construction.
The API serves its own spec at GET /v1/openapi.json (no authentication required), so you can generate against any environment you can reach.
1. Generate types with openapi-typescript
openapi-typescript converts the spec into a single .ts file of types, with zero runtime code.
npm install -D openapi-typescript typescript
npx openapi-typescript "$OUTPOST_URL/v1/openapi.json" -o ./src/outpost-api.tsRe-run the command whenever the API changes; the diff of the generated file shows you exactly what changed in the contract.
2. Call the API with openapi-fetch
openapi-fetch is a tiny (~6 kB) fetch wrapper that consumes those types. Paths, methods, path/query parameters, request bodies, and response shapes are all checked at compile time.
npm install openapi-fetchimport createClient from 'openapi-fetch';
import type { paths } from './outpost-api';
const api = createClient<paths>({
baseUrl: process.env.OUTPOST_URL,
headers: { 'x-api-key': process.env.OUTPOST_API_KEY },
});
// Fully typed: TypeScript knows this endpoint, its body shape, and its 202 response.
const { data, error } = await api.POST('/v1/messages/sms', {
body: {
items: [{ to: '+15551234567', body: 'Hello from Outpost!' }],
communicationId: 'welcome-blast-1',
},
});
if (error) {
// `error` is the typed error response body.
console.error('Send failed:', error);
} else {
// `data` is the typed 202 payload with per-item outcomes.
console.log('Accepted:', data.accepted, 'Rejected:', data.rejected);
}Every request returns { data, error } rather than throwing, and both sides are typed from the spec. A typo in a path, a missing required field, or reading a property that does not exist on the response is a compile error, not a production bug.
Authentication is a project-scoped API key in the x-api-key header. See API Keys & Authentication for roles and scoping.
Inside the Outpost monorepo
The dashboard follows the same generate-from-spec path as any other TypeScript consumer. Types are produced from the committed document at packages/api/openapi.json (npm run generate:api in packages/dashboard, hooked to predev / prebuild).
After changing an API route schema, regenerate the committed document first:
npm run generate:openapi -w @outpost/apiOther languages
The spec is a standard OpenAPI 3.1 document, so any OpenAPI generator works, for example openapi-generator for Python, Go, Java, and others:
openapi-generator generate -i "$OUTPOST_URL/v1/openapi.json" -g python -o ./outpost-clientBrowsing the contract
The full endpoint-by-endpoint contract, with schemas and error responses, lives in the API Reference section of these docs, generated from the same OpenAPI document.