Generate a TypeScript SDK from your OpenAPI spec
Octri reads your OpenAPI document and writes a TypeScript client with types from your schemas, publishes it to npm under your own package name, and rebuilds it every time the spec changes.
npm install @acme/apiThe client they actually get
What your users write once the TypeScript package is installed.
Two call-site shapes come out of the same spec. class-namespaced is the default: a client object whose operations are grouped by resource, which is the surface every widely used SDK ships and the one your own reference docs already assume. functions is the override, and it is the one to reach for when your users care about tree-shaking. It is a single setting, per language, and nothing else about the client changes with it.
Types come from your schemas either way, so a renamed field is a compile error in your users’ editors rather than an undefined at runtime.
Scoped or unscoped, published under your own account. npm does not allow renaming and will not republish a deleted version, so the first release claims the name for good.
import { Acme } from "@acme/api";
const acme = new Acme({
baseUrl: "https://api.acme.com/v1",
auth: { bearerAuth: process.env.ACME_TOKEN },
});
// A paginated operation IS an async generator. The loop pulls the next page,
// and nothing is prefetched.
for await (const user of acme.users.list({ limit: 100 })) {
console.log(user.id);
}
const invoice = await acme.invoices.create({
customerId: "cus_123",
amountCents: 4900,
});import { configureClient, listUsers, createInvoice } from "@acme/api";
configureClient({
baseUrl: "https://api.acme.com/v1",
auth: { bearerAuth: process.env.ACME_TOKEN },
});
for await (const user of listUsers({ limit: 100 })) {
console.log(user.id);
}
const invoice = await createInvoice({ customerId: "cus_123", amountCents: 4900 });What you decide for TypeScript
Set project-wide, or per language when TypeScript wants something the others do not. Defaults are the shape TypeScript SDKs actually ship.
Client style
class-namespaced (default), class, namespaced, functionsA client object whose operations are grouped by resource is the default, because it is the surface every widely used SDK ships and the one your reference docs already assume. Free functions are the override, and they tree-shake.
HTTP engine
fetch (default), axiosfetch keeps the package dependency-free on Node 18+, browsers, Deno, Bun and edge runtimes. axios buys interceptors at the cost of a dependency in your users’ bundles.
Argument style
object (default), positionalAn options object survives a new optional parameter. Positional arguments do not.
Method naming
short (default), fullShort strips the namespace word, so getBalance under balance becomes balance.get(). Full keeps the operationId as written.
Namespace
tags (default), pathTags decide whether a caller writes client.invoices.list() or client.v1.list().
Decide this before the first release
The npm name is permanent
npm has no rename, and it refuses to republish a version you deleted. A scoped name (@acme/api) is namespaced to your organisation, cannot be squatted, and reads unambiguously beside your other packages. Decide it before the first publish rather than after.
In every generated client, not just this one
The parts nobody wants to hand-write, and the parts a hand-written client usually skips.
- Retries with exponential backoff and jitter, on the statuses that mean "try again", with a per-attempt timeout.
- Idempotency keys on the methods that need them, so a retried write does not become two.
- Auth wired in from your spec’s security scheme, read from wherever your users keep secrets.
- Typed errors split by cause: a failed constraint, an HTTP status, a network failure and a timeout are four different things.
- Pagination that follows whichever contract your spec declares, cursor, offset, page number or next URL, without prefetching the collection.
- Server-sent events as a native stream, for the operations that stream.
- Error reporting to Octri’s monitoring, pre-wired and switched off until a consumer opts in.
Point it at your spec
Upload an OpenAPI or Swagger document, paste a URL, or connect the repository it lives in so a merge to main updates it.
Read the audit
The spec is scored out of 10 on what a generator can do with it, with every missing schema and colliding operationId named. 9 of the fourteen rules carry a button that writes the fix.
Shape the client
Client style, argument style, namespacing, auth, retries and pagination, set once for the project and overridden per language or per endpoint.
Generate and read it
The package is generated, compiled and handed to you as source you can read before anyone installs it.
Publish, then keep publishing
Release to the registry under your own account. Every later spec change regenerates the client, and the version comes from your document rather than from us.
Or in another language
One spec, ten languages. These three are generated from the same document, with the same settings, at the same time.
Questions
It is TypeScript source. Types are generated from your schemas alongside the methods, so there is no hand-written declaration file to keep in step.