api-codegen
API client code generation workflow. Use when modifying backend routes, response schemas, or request models. Automatically regenerates TypeScript API client from OpenAPI schema.
Best use case
api-codegen is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
API client code generation workflow. Use when modifying backend routes, response schemas, or request models. Automatically regenerates TypeScript API client from OpenAPI schema.
Teams using api-codegen should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/api-codegen/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How api-codegen Compares
| Feature / Agent | api-codegen | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
API client code generation workflow. Use when modifying backend routes, response schemas, or request models. Automatically regenerates TypeScript API client from OpenAPI schema.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# API Client Code Generation
This skill manages the workflow for keeping the frontend TypeScript API client in sync with the backend.
## When to use this skill
- After modifying Litestar routes in `backend/app/`
- After changing request/response schemas (msgspec)
- After adding new API endpoints
- When frontend TypeScript errors mention missing types
- Before committing changes that affect the API contract
## Quick Command
```bash
make codegen # Generate TypeScript API client from backend OpenAPI schema
```
## Complete Workflow
1. **Modify backend** (routes, schemas, endpoints)
- Edit Litestar route handlers in `backend/app/server/`
- Update msgspec schemas in `backend/app/domain/*/schemas.py`
- Add new endpoints or modify existing ones
2. **Generate API client**
```bash
make codegen
```
This will:
- Start the backend server temporarily
- Fetch OpenAPI schema from `/schema/openapi.json`
- Generate TypeScript client in `frontend/src/openapi/`
- Stop the backend server
3. **Verify generation**
- Check `frontend/src/openapi/` for new types
- Review generated request/response interfaces
- Look for any generation warnings
4. **Update frontend code**
- Import new types from `@/openapi`
- Use generated API client methods
- Fix any TypeScript errors
5. **Type check**
```bash
make check-frontend # Verify TypeScript compilation
```
## What Gets Generated
The codegen process creates:
- **Type definitions**: Request/response interfaces
- **API client methods**: Type-safe API calls
- **Enums and constants**: From backend schemas
- **Path parameters**: Type-safe route params
Location: `frontend/src/openapi/`
## Example Usage
### Backend Schema (msgspec)
```python
# backend/app/domain/users/schemas.py
from msgspec import Struct
class UserCreateRequest(Struct):
email: str
name: str
class UserResponse(Struct):
id: int
email: str
name: str
created_at: str
```
### Generated TypeScript
```typescript
// frontend/src/openapi/models.ts
export interface UserCreateRequest {
email: string;
name: string;
}
export interface UserResponse {
id: number;
email: string;
name: string;
created_at: string;
}
```
### Frontend Usage
```typescript
import { api } from '@/openapi';
import type { UserCreateRequest, UserResponse } from '@/openapi';
const createUser = async (data: UserCreateRequest): Promise<UserResponse> => {
const response = await api.users.create(data);
return response;
};
```
## Troubleshooting
### Generation fails
- **Backend not starting**: Check for syntax errors in Python code
- **Port 8000 in use**: Stop existing backend process
- **OpenAPI schema errors**: Verify all route handlers have proper schemas
### Types missing after generation
- **Endpoint not in OpenAPI**: Ensure route is registered in Litestar app
- **Schema not exported**: Check msgspec Struct definitions
- **Route tags**: Verify API grouping/tagging
### Frontend TypeScript errors after codegen
- **Incompatible changes**: Breaking API changes require frontend updates
- **Missing imports**: Update imports to use new generated types
- **Deprecated types**: Remove references to old type names
## Best Practices
1. **Run codegen frequently**: After any backend schema changes
2. **Commit generated files**: Include `frontend/src/openapi/` in commits
3. **Review changes**: Check git diff for generated code changes
4. **Type safety**: Let TypeScript catch API contract mismatches
5. **Breaking changes**: Coordinate with frontend team for major API changes
## Integration with Development Workflow
### Making API Changes
1. Modify backend route/schema
2. Run `make codegen`
3. Update frontend code to use new types
4. Run `make check-frontend`
5. Test changes locally
6. Commit all changes together (backend + frontend + generated)
### Before Pull Request
```bash
make codegen # Regenerate API client
make check-all # Type check everything
make test # Run backend tests
```
This ensures the API contract is in sync across the full stack.Related Skills
abi-codegen
Convert JSON ABI files to TypeScript const exports with proper typing. Use when working with smart contract ABIs, converting JSON to TypeScript, generating typed contract interfaces, or adding new contract ABIs to the SDK.
bgo
Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.
acc-create-bulkhead
Generates Bulkhead pattern for PHP 8.5. Creates resource isolation with semaphore-based concurrency limiting and thread pool isolation. Includes unit tests.
acc-create-anti-corruption-layer
Generates DDD Anti-Corruption Layer for PHP 8.5. Creates translation layer between bounded contexts or external systems. Includes adapters, translators, facades, and unit tests.
acc-create-action
Generates ADR Action classes for PHP 8.5. Creates single-responsibility HTTP endpoint handlers with PSR-7 support. Includes unit tests.
acc-clean-arch-knowledge
Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.
acc-claude-code-knowledge
Knowledge base for Claude Code formats and patterns. Use when creating or improving commands, agents, skills, or hooks.
acc-check-leaky-abstractions
Detects leaky abstractions in PHP code. Identifies implementation details exposed in interfaces, concrete returns from abstract methods, framework leakage into domain, and infrastructure concerns in application layer.
acc-check-encapsulation
Analyzes PHP code for encapsulation violations. Detects public mutable state, exposed internals, Tell Don't Ask violations, getter/setter abuse, and information hiding breaches.
acc-check-bounded-contexts
Analyzes bounded context boundaries in DDD projects. Detects cross-context coupling, shared kernel violations, context mapping issues, and ubiquitous language inconsistencies. Generates context map diagrams and boundary recommendations.
acc-architecture-doc-template
Generates ARCHITECTURE.md files for PHP projects. Creates layer documentation, component descriptions, and architectural diagrams.
acc-api-doc-template
Generates API documentation for PHP projects. Creates endpoint documentation with parameters, responses, and examples.