Skip to main content

Client Generation

One of the best things about Contract is that you can generate typed clients in any language. Your Go service becomes a TypeScript client, Python client, or any other language - with full type safety.
Native SDK Generation: Mizu now includes built-in SDK generators for Go, Python, and TypeScript that produce idiomatic, zero-dependency clients with better developer experience than OpenAPI-based generation. See SDK Generation for details.

Two Approaches to Client Generation

Native SDK Generation

Built-in generators for Go, Python, and TypeScript with OpenAI-style developer experience

OpenAPI Generation

Use OpenAPI spec with third-party generators for any language (continue reading below)

How It Works

Contract provides machine-readable descriptions of your API:

Two Ways to Get API Metadata

OpenAPI Client Generation

OpenAPI has the most mature tooling. This is the recommended approach.

Step 1: Serve OpenAPI Spec

Step 2: Download the Spec

Step 3: Generate Clients

Use any OpenAPI code generator. Here are the most popular:

TypeScript

Using openapi-typescript (types only):
Using openapi-typescript-codegen (full client):
Using openapi-generator:

Python

Using openapi-python-client:
Using openapi-generator:

Go

Using oapi-codegen:
Using openapi-generator:

Other Languages

Handwritten Clients

Sometimes you don’t need code generation - a simple handwritten client works fine.

Go Client

Usage:

Python Client

Usage:

JSON-RPC Client

For JSON-RPC transport, clients need to handle the JSON-RPC envelope:

TypeScript

Error Handling in Clients

Always handle errors properly in your clients:

TypeScript

Go

Automation with CI/CD

Automate client generation in your build:

GitHub Action

Best Practices

1. Version Your API

Include version in your service:

2. Keep Clients in Sync

Regenerate clients when your API changes. Consider:
  • Git submodules for shared clients
  • Package registry (npm, PyPI) for versioned clients
  • API versioning for breaking changes

3. Add Custom Headers

Clients often need authentication:

4. Handle Rate Limits

See Also