Request Flow
Detailed sequence diagrams for all request types.
MCP Request Flow
Image Generation

Complete request flow from MCP client through Gemini API to storage
Continue Editing

Edit last image: get session, download, edit, update session
Character Generation

Load character, fetch references, build prompt, generate
REST API Flow
Get Images List

Authenticate, query D1 with filters, return JSON response
Admin Create Tenant

Validate admin, generate credentials, insert into D1 and KV
Authentication Flow
API Key Validation

Extract key, validate format, check cache/D1, decrypt, return tenant
Admin Token Validation

Check admin token header, validate, process or reject
Error Handling Flow

Auth → Rate limit → Quota → Tool execution → Response
Transport Protocols
Streamable HTTP (Recommended)

POST /mcp with streaming response for progress updates
Server-Sent Events (Legacy)

GET /sse opens connection, events pushed to client
Parallel Processing
Multi-Image Generation

Generate n=4 images in parallel from Gemini API
Multi-Character Scene

Parallel load characters, fetch refs, combine prompts
Response Formats
Success Response
json
{
"content": [
{
"type": "text",
"text": "Generated successfully\n\nImage #342\nURL: https://..."
}
]
}Error Response
json
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded",
"details": {
"limit": 60,
"window": "1 minute",
"retry_after": 30
}
}
}