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
| Approach | Best For | Pros | Cons |
|---|---|---|---|
| Native SDKs | Go, Python, TypeScript | Idiomatic code, zero deps, better DX, streaming support | Limited language support |
| OpenAPI (this page) | Other languages, ecosystem compatibility | 40+ languages, mature tooling | Generic code, more dependencies |
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
| Endpoint | Format | Best For |
|---|---|---|
/openapi.json | OpenAPI 3.1 | Most languages, best tooling |
/mcp (tools/list) | MCP tools | AI assistants |
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
Usingopenapi-typescript (types only):
openapi-typescript-codegen (full client):
openapi-generator:
Python
Usingopenapi-python-client:
openapi-generator:
Go
Usingoapi-codegen:
openapi-generator:
Other Languages
Handwritten Clients
Sometimes you don’t need code generation - a simple handwritten client works fine.Go Client
Python Client
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
- SDK Generation - Native SDK generators for Go, Python, TypeScript
- Go SDK - Native Go client generation
- Python SDK - Native Python client generation
- TypeScript SDK - Native TypeScript client generation
- OpenAPI - OpenAPI specification generation
- REST - REST endpoints
- JSON-RPC - JSON-RPC endpoints
- MCP - MCP for AI assistants