The --type flag enables automatic TypeScript type generation from API responses. ByteKit fetches the endpoint, analyzes the response structure, and creates type-safe interfaces.
Basic Usage
bytekit --type https://api.example.com/users
This command:
Fetches the API endpoint
Analyzes the JSON response structure
Generates TypeScript types
Saves to src/types/{endpoint}.ts
Command Flags
--method=<METHOD>
Specify the HTTP method for the request:
bytekit --type --method=POST https://api.example.com/users
Supported methods:
GET (default)
POST
PUT
PATCH
DELETE
--body=<json>
Include a JSON body in the request:
bytekit --type --method=POST --body= '{"name":"John","email":"john@example.com"}' https://api.example.com/users
Add custom HTTP headers (can be used multiple times):
bytekit --type --header= "Authorization: Bearer token123" https://api.example.com/protected
Multiple headers:
bytekit --type \
--header= "Authorization: Bearer token123" \
--header= "Content-Type: application/json" \
--header= "X-Custom-Header: value" \
https://api.example.com/data
Headers support values with colons (e.g., Authorization: Bearer key:123). Only the first colon is used as the separator.
Examples with Different HTTP Methods
GET Request
Fetch user data and generate types:
bytekit --type https://jsonplaceholder.typicode.com/users/1
Output:
📡 Fetching GET https://jsonplaceholder.typicode.com/users/1...
✅ Types generated successfully!
📝 Output: /home/user/project/src/types/users.ts
Generated types:
──────────────────────────────────────────────────
// Auto-generated types from API response
// Generated at 2026-03-04T10:30:00.000Z
export interface Users {
id: number;
name: string;
username: string;
email: string;
address: {
street: string;
suite: string;
city: string;
zipcode: string;
geo: {
lat: string;
lng: string;
};
};
phone: string;
website: string;
company: {
name: string;
catchPhrase: string;
bs: string;
};
}
──────────────────────────────────────────────────
POST Request
Generate types from a POST endpoint:
bytekit --type --method=POST --body= '{"title":"Test","body":"Content","userId":1}' https://jsonplaceholder.typicode.com/posts
Generated output:
// Auto-generated types from API response
// Generated at 2026-03-04T10:35:00.000Z
export interface Posts {
id : number ;
title : string ;
body : string ;
userId : number ;
}
Update a resource and generate types:
bytekit --type \
--method=PUT \
--body= '{"title":"Updated Title"}' \
--header= "Authorization: Bearer abc123" \
https://api.example.com/posts/1
DELETE Request
Generate types from a DELETE response:
bytekit --type --method=DELETE https://api.example.com/users/123
Type Inference
ByteKit intelligently infers TypeScript types from JSON data:
Primitive Types
JSON Value TypeScript Type "hello"string42numbertruebooleannullnull
Complex Types
Arrays:
Objects:
{ "name" : "John" , "age" : 30 }
export interface Data {
name : string ;
age : number ;
}
Nested Objects:
{
"user" : {
"profile" : {
"email" : "test@example.com"
}
}
}
export interface Data {
user : {
profile : {
email : string ;
};
};
}
Mixed Arrays:
type Data = ( number | string | boolean )[];
Optional Properties
Null or undefined values are marked as optional:
{ "name" : "John" , "email" : null }
export interface Data {
name : string ;
email ?: null ;
}
File Output
Output Location
Types are saved to src/types/{endpoint}.ts where {endpoint} is derived from the URL path:
bytekit --type https://api.example.com/users
# → src/types/users.ts
bytekit --type https://api.example.com/posts/123
# → src/types/posts.ts
bytekit --type https://api.example.com/api/v1/products
# → src/types/products.ts
Interface Naming
The interface name is automatically capitalized from the endpoint:
/users → Users
/posts → Posts
/products → Products
All generated files include:
Auto-generation comment
Timestamp
Exported interface
// Auto-generated types from API response
// Generated at 2026-03-04T10:30:00.000Z
export interface Users {
// ... properties
}
Real-World Examples
GitHub API
Generate types for GitHub repositories:
bytekit --type https://api.github.com/repos/microsoft/typescript
JSONPlaceholder
Generate types for todos:
bytekit --type https://jsonplaceholder.typicode.com/todos/1
Output:
export interface Todos {
userId : number ;
id : number ;
title : string ;
completed : boolean ;
}
Authenticated API
Generate types from a protected endpoint:
bytekit --type \
--header= "Authorization: Bearer your_token_here" \
https://api.example.com/me
Creating a New Resource
Generate types from a POST request:
bytekit --type \
--method=POST \
--body= '{"username":"johndoe","email":"john@example.com"}' \
--header= "Content-Type: application/json" \
https://api.example.com/register
Error Handling
The CLI provides detailed error messages:
HTTP Error:
bytekit --type https://api.example.com/notfound
# ❌ Error: HTTP 404: Not Found
Network Error:
bytekit --type https://invalid-domain.example
# ❌ Error: fetch failed
Invalid JSON:
bytekit --type https://example.com/not-json
# ❌ Error: Unexpected token < in JSON at position 0
Tips and Best Practices
Use sample data endpoints: For best results, fetch endpoints that return representative sample data with all possible fields populated.
Empty arrays ([]) are typed as unknown[] since ByteKit cannot infer the element type without sample data.
Generated types are a starting point. You may need to refine them for edge cases or add additional validation.
Next Steps
Swagger Integration Generate types from complete OpenAPI/Swagger specifications