'use client'; /** * API Reference: Text to Image * * Refactored to use block components from @/components/docs/blocks * Demonstrates API documentation patterns with semantic components */ import { DocsLayout } from '@/components/docs/layout/DocsLayout'; import { DocsSidebar } from '@/components/docs/layout/DocsSidebar'; import { DocsTOC } from '@/components/docs/layout/DocsTOC'; import { SubsectionNav } from '@/components/shared/SubsectionNav'; import { TipBox } from '@/components/docs/shared/TipBox'; import { Table } from '@/components/docs/shared/Table'; import { Breadcrumb } from '@/components/docs/shared/Breadcrumb'; import { CodeBlock } from '@/components/docs/shared/CodeBlock'; import { InteractiveAPIWidget } from '@/components/docs/blocks/InteractiveAPIWidget'; import { Hero, SectionHeader, InlineCode, EndpointCard, LinkCard, LinkCardGrid, } from '@/components/docs/blocks'; const tocItems = [ { id: 'overview', text: 'Overview', level: 2 }, { id: 'endpoint', text: 'Endpoint', level: 2 }, { id: 'parameters', text: 'Parameters', level: 2 }, { id: 'response', text: 'Response', level: 2 }, { id: 'error-codes', text: 'Error Codes', level: 2 }, { id: 'interactive', text: 'Try It Live', level: 2 }, { id: 'next-steps', text: 'Next Steps', level: 2 }, ]; const navItems = [ { label: 'Documentation', href: '/docs' }, { label: 'Demo', href: '/demo' }, { label: 'Examples', href: '/docs/examples' }, ]; const parameters = [ { name: 'prompt', type: 'string', required: true, description: 'Text description of the image to generate' }, { name: 'filename', type: 'string', required: false, description: 'Output filename (without extension)' }, { name: 'aspectRatio', type: 'string', required: false, description: 'Image aspect ratio: "1:1", "16:9", "9:16", "4:3"' }, { name: 'autoEnhance', type: 'boolean', required: false, description: 'Enable AI prompt enhancement for better results' }, ]; export default function TextToImageAPIPage() { return ( <> {/* Subsection Navigation with API Key Input */} } toc={} > {/* Hero Section */} {/* Overview */}
Overview

The Text to Image endpoint allows you to generate images from natural language descriptions. Powered by Google Gemini 2.5 Flash and Imagen 4.0, it produces photorealistic images optimized for your specified requirements.

Tip: Enable autoEnhance to let AI improve your prompts for better image quality.
{/* Endpoint */}
Endpoint
{/* Parameters */}
Parameters

All parameters should be sent in the request body as JSON.

[ {param.name}, {param.type}, {param.required ? 'Yes' : 'No'} , param.description, ])} />
Default Values: If not specified, filename is auto-generated, aspectRatio defaults to "1:1", and autoEnhance is false.
{/* Response */}
Response

On success, the API returns a JSON object containing the generated image URL and metadata.

{/* Error Codes */}
Error Codes

The API uses standard HTTP status codes and returns descriptive error messages.

400, 'Bad Request', 'Missing or invalid parameters in the request body', ], [ 401, 'Unauthorized', 'Missing or invalid API key in X-API-Key header', ], [ 429, 'Rate Limit', 'Too many requests. Check rate limit headers for retry timing', ], [ 500, 'Server Error', 'Internal server error. Contact support if persists', ], ]} />
Rate Limits: Project API keys are limited to 100 requests per hour. Upgrade your plan for higher limits.
{/* Interactive Widget */}
Try It Live

Test the API directly from this page. Enter your API key and customize the parameters below.

{/* Next Steps */}
Next Steps
); }