> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routeway.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generations

> Generate one or more images from a text prompt. Supports both synchronous and asynchronous modes.

This API endpoint allows you to generate images from text prompts using various image generation models.

<Warning>
  Images stored via URL are only available for 1 hour after generation. Make sure to download and save important images locally.
</Warning>

## Create Image Generation

To generate an image, use the following endpoint:

`POST /v1/images/generations`

### Request Body

<ParamField body="model" type="string" required>
  The image generation model to use (e.g., "flux-1-schnell")
</ParamField>

<ParamField body="prompt" type="string" required>
  The text prompt for image generation
</ParamField>

<ParamField body="quality" type="string">
  Provider-specific quality preset
</ParamField>

<ParamField body="size" type="string">
  Target image resolution (e.g., "1024x1024")
</ParamField>

<ParamField body="n" type="integer">
  Number of images to generate (default: 1)
</ParamField>

<RequestExample>
  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.routeway.ai/v1",
      api_key=os.getenv("Routeway_API_KEY")
  )

  response = client.images.generate(
      model="flux-1-schnell",
      prompt="A beautiful sunset over a mountain lake",
      size="1024x1024",
      n=1,
      quality="standard"
  )

  print(response.data[0].url)
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios')

  const apiKey = 'your_routeway_api_key'
  const url = 'https://api.routeway.ai/v1/images/generations'

  const data = {
  	model: 'flux-1-schnell',
  	prompt: 'A futuristic city with flying cars',
  	size: '1024x1024',
  	n: 1
  }

  const headers = {
  	'Content-Type': 'application/json',
  	Authorization: `Bearer ${apiKey}`,
  }

  axios
  	.post(url, data, { headers })
  	.then(response => {
  		console.log(response.data)
  	})
  	.catch(error => {
  		console.error('Error:', error)
  	})
  ```

  ```bash cURL theme={null}
  curl https://api.routeway.ai/v1/images/generations \
    -H "Authorization: Bearer $Routeway_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "flux-1-schnell",
      "prompt": "A serene garden with cherry blossoms",
      "size": "1024x1024",
      "n": 1
    }'
  ```
</RequestExample>


## OpenAPI

````yaml POST /v1/images/generations
openapi: 3.1.0
info:
  title: Routeway API
  version: 1.0.0
servers:
  - url: https://api.routeway.ai
security:
  - HTTPBearer: []
paths:
  /v1/images/generations:
    post:
      tags:
        - Images
      summary: Generate Image (v1)
      description: >-
        Generate one or more images from a text prompt. Supports both
        synchronous and asynchronous modes.
      operationId: image_generations_v1_images_generations_post
      parameters:
        - name: x-api-key
          in: header
          required: false
          schema:
            type: string
            title: X-Api-Key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageGenerationResponse'
        '400':
          description: Bad Request - Invalid query parameters or body format.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden - Key does not have permission or is disabled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable Entity - Request body validation failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Too Many Requests - Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error - Internal error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: Bad Gateway - Provider error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ImageGenerationRequest:
      properties:
        model:
          type: string
          title: Model
          description: Image generation model (e.g., flux-1-schnell)
        prompt:
          type: string
          title: Prompt
          description: The text prompt for image generation
        quality:
          anyOf:
            - type: string
            - type: 'null'
          title: Quality
          description: Provider-specific quality preset
        size:
          anyOf:
            - type: string
            - type: 'null'
          title: Size
          description: Target image resolution (e.g., 1024x1024)
        'n':
          anyOf:
            - type: integer
            - type: 'null'
          title: 'N'
          description: Number of images to generate
          default: 1
        response_format:
          type: string
          enum:
            - url
            - b64_json
          title: Response Format
          description: Output format per image
          default: url
        steps:
          anyOf:
            - type: integer
            - type: 'null'
          title: Steps
          description: Number of diffusion steps
        seed:
          anyOf:
            - type: integer
            - type: 'null'
          title: Seed
          description: Random seed for reproducibility
        negative_prompt:
          anyOf:
            - type: string
            - type: 'null'
          title: Negative Prompt
          description: Negative prompt for image generation
        guidance:
          anyOf:
            - type: number
            - type: 'null'
          title: Guidance
          description: Guidance scale for image generation
        async:
          type: boolean
          title: Async
          description: >-
            Queue the request and return a task ID instead of waiting for the
            image result
          default: false
      additionalProperties: false
      type: object
      required:
        - model
        - prompt
      title: ImageGenerationRequest
    ImageGenerationResponse:
      properties:
        created:
          type: integer
          title: Created
          description: Unix timestamp of request creation
        data:
          items:
            $ref: '#/components/schemas/ImageData'
          type: array
          title: Data
          description: Array of generated image objects
      type: object
      required:
        - created
        - data
      title: ImageGenerationResponse
    ErrorResponse:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      type: object
      required:
        - error
      title: ErrorResponse
    ImageData:
      properties:
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
          description: Image URL (when response_format is 'url')
        b64_json:
          anyOf:
            - type: string
            - type: 'null'
          title: B64 Json
          description: Base64-encoded image (when response_format is 'b64_json')
        revised_prompt:
          anyOf:
            - type: string
            - type: 'null'
          title: Revised Prompt
          description: The actual prompt used after any modifications
      type: object
      title: ImageData
    ErrorDetail:
      properties:
        message:
          type: string
          title: Message
          description: A human-readable description of the error.
        type:
          type: string
          title: Type
          description: >-
            The type of error returned (e.g. invalid_request_error,
            rate_limit_error).
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
          description: The parameter that caused the error, if applicable.
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
          description: >-
            A short code identifier for the error type (e.g. invalid_request,
            rate_limit).
        status_code:
          type: integer
          title: Status Code
          description: The HTTP status code.
        id:
          type: string
          title: Id
          description: Unique error or trace ID associated with this request.
        tip:
          anyOf:
            - type: string
            - type: 'null'
          title: Tip
          description: An optional troubleshooting tip or resolution suggestion.
        docs:
          anyOf:
            - type: string
            - type: 'null'
          title: Docs
          description: Link to the documentation related to this error.
          default: https://docs.routeway.ai
        support:
          anyOf:
            - type: string
            - type: 'null'
          title: Support
          description: Link to support for further help.
          default: https://discord.gg/RjX2CpdPpd
        community:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Community
          description: Links to community resources like Discord and Twitter.
      type: object
      required:
        - message
        - type
        - status_code
        - id
      title: ErrorDetail
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````