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

# Generate an image

> Generate one or more images from a text prompt. Beyond the standard fields, each model accepts its own **model-specific** sizing and quality parameters such as `resolution`, `aspect_ratio`, `width`/`height`, and `quality`. Send the ones your chosen model supports. Call `GET /v1/models` to see each model's supported parameters; pricing is shown on deepshi.ai and every response returns the actual `usage.cost`. Set `stream: true` for Server-Sent Events on slow, high-resolution generations.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/images/generations
openapi: 3.1.0
info:
  title: Deepshi API
  description: >-
    OpenAI-compatible REST API for Deepshi's own models and leading third-party
    models. Authenticate with your Deepshi API key as a bearer token, and
    reference a model by its id (e.g. `deepshi-3.0`, `gpt-4o`) in the `model`
    field.
  version: 1.0.0
servers:
  - url: https://api.deepshi.ai
    description: Deepshi API
security:
  - BearerAuth: []
paths:
  /v1/images/generations:
    post:
      tags:
        - Images
      summary: Generate an image
      description: >-
        Generate one or more images from a text prompt. Beyond the standard
        fields, each model accepts its own **model-specific** sizing and quality
        parameters such as `resolution`, `aspect_ratio`, `width`/`height`, and
        `quality`. Send the ones your chosen model supports. Call `GET
        /v1/models` to see each model's supported parameters; pricing is shown
        on deepshi.ai and every response returns the actual `usage.cost`. Set
        `stream: true` for Server-Sent Events on slow, high-resolution
        generations.
      operationId: createImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
      responses:
        '200':
          description: >-
            The generated image(s). When `stream: true`, the response is a
            Server-Sent Events stream (`text/event-stream`): periodic keepalive
            comments followed by a terminal `image_generation.completed` event
            carrying the final image (see the `ImageStreamEvent` schema).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ImageStreamEvent'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientQuota'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    ImageGenerationRequest:
      type: object
      description: >-
        Image generation request. `model` and `prompt` are required. The
        remaining fields are optional; a model safely ignores any field it does
        not support. Model-specific sizing/quality fields (`width`/`height`,
        `aspect_ratio`, `resolution`, `quality`, `image_size`) apply only to the
        models that declare them — see `GET /v1/models`. Additional
        model-specific parameters not listed here may also be sent and are
        forwarded to the model.
      required:
        - model
        - prompt
      additionalProperties: true
      properties:
        model:
          type: string
          description: The image model id to use. See `GET /v1/models`.
          example: nano-banana-pro
        prompt:
          type: string
          description: Text description of the image to generate.
          example: a serene canal in Venice at sunset
        'n':
          type: integer
          description: Number of images to generate (1–4).
          minimum: 1
          maximum: 4
          default: 1
        response_format:
          type: string
          description: >-
            How images are returned. `url` returns an inline base64 `data:` URI,
            not a hosted link.
          enum:
            - b64_json
            - url
          default: b64_json
        output_format:
          type: string
          description: Encoding of the returned image. Not all models honor every format.
          enum:
            - png
            - jpeg
            - webp
        stream:
          type: boolean
          description: >-
            Stream the result as Server-Sent Events. Use it for slow,
            high-resolution generations that would otherwise time out.
          default: false
        seed:
          type: integer
          description: Seed for reproducible output. Omit for a random seed.
        width:
          type: integer
          description: >-
            Model-specific. Output width in pixels, for pixel-dimension models
            (e.g. `flux-2-pro`).
        height:
          type: integer
          description: Model-specific. Output height in pixels, for pixel-dimension models.
        aspect_ratio:
          type: string
          description: >-
            Model-specific. Aspect ratio for aspect-ratio and resolution-tier
            models.
          example: '16:9'
        resolution:
          type: string
          description: >-
            Model-specific. Resolution tier for resolution-tier models (e.g.
            `nano-banana-2`, `nano-banana-pro`, `grok-imagine-quality`).
            Determines the billed price for those models.
          example: 2K
        quality:
          type: string
          description: >-
            Model-specific. Quality tier for the GPT Image models
            (`gpt-image-1.5`, `gpt-image-2`). Higher tiers cost more, and the
            price depends on the image size and quality you pick. Omit to use
            the model's default tier.
          enum:
            - low
            - medium
            - high
        image_size:
          type: string
          description: >-
            Model-specific. Named output size for preset-size models (e.g.
            `seedream-4.5`).
          example: auto_2K
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          format: int64
          description: Unix timestamp when the request was created.
        model:
          type: string
          description: The image model id you requested.
        size:
          type: string
          description: The actual output dimensions, as `WIDTHxHEIGHT`.
        data:
          type: array
          items:
            $ref: '#/components/schemas/ImageData'
          description: The generated image(s).
        usage:
          $ref: '#/components/schemas/Usage'
    ImageStreamEvent:
      type: object
      description: >-
        One Server-Sent Event from a streamed image request (`stream: true`).
        The stream sends keepalive comments, then a terminal
        `image_generation.completed` event carrying the final image and usage.
        Note the flat shape: `b64_json` is top-level here, not nested under
        `data[]` as in the non-streamed `ImageResponse`.
      properties:
        type:
          type: string
          description: Event type.
          example: image_generation.completed
        b64_json:
          type: string
          description: Base64-encoded image, present on the completed event.
        size:
          type: string
          description: Output dimensions of the image.
          example: 1024x1024
        usage:
          $ref: '#/components/schemas/Usage'
    ImageData:
      type: object
      required:
        - index
      properties:
        b64_json:
          type: string
          nullable: true
          description: >-
            Base64-encoded image. Present when `response_format` is `b64_json`
            (the default).
        url:
          type: string
          nullable: true
          description: >-
            Inline `data:` URI for the image. Present when `response_format` is
            `url`.
        revised_prompt:
          type: string
          nullable: true
          description: The prompt actually used, if the model revised it.
        index:
          type: integer
          description: Position of this image in the batch.
    Usage:
      type: object
      description: Token usage and the billed cost for the request.
      properties:
        prompt_tokens:
          type: integer
          description: Total input tokens (includes any cached tokens).
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
            cached_read_tokens:
              type: integer
              description: >-
                Tokens served from the prompt cache, billed at the cache-read
                rate.
            image_tokens:
              type: integer
        completion_tokens:
          type: integer
          description: >-
            Output tokens generated (includes reasoning tokens for reasoning
            models).
        completion_tokens_details:
          type: object
          properties:
            reasoning_tokens:
              type: integer
            image_tokens:
              type: integer
        total_tokens:
          type: integer
        cost:
          $ref: '#/components/schemas/Cost'
    Error:
      type: object
      description: Error envelope, matching the OpenAI shape.
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable description of the error.
            type:
              type: string
              description: >-
                Error category, e.g. `invalid_request_error` or
                `insufficient_quota`.
            code:
              type: string
              nullable: true
              description: >-
                Machine-readable error code, e.g. `invalid_api_key`,
                `model_not_found`, `insufficient_quota` (may be null).
            param:
              type: string
              nullable: true
              description: The request parameter the error relates to, when applicable.
    Cost:
      type: object
      description: >-
        Deepshi extension: the exact USD amount this request deducted from your
        balance. Standard OpenAI SDKs ignore it.
      properties:
        total_cost:
          type: number
          description: USD cost deducted from your balance for this request.
          example: 0.000135
  responses:
    BadRequest:
      description: Malformed request, or a model id that doesn't exist in the catalog.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: The model does not exist or you do not have access to it.
              type: invalid_request_error
              code: model_not_found
              param: null
    Unauthorized:
      description: Missing, malformed, or unknown API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Incorrect API key provided.
              type: invalid_request_error
              code: invalid_api_key
              param: null
    InsufficientQuota:
      description: The account is out of credits.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: You have insufficient credits to complete this request.
              type: insufficient_quota
              code: insufficient_quota
              param: null
    Forbidden:
      description: The key is revoked, or not permitted to use the requested model.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: The model does not exist or you do not have access to it.
              type: invalid_request_error
              code: model_not_found
              param: null
    RateLimited:
      description: Too many requests. Back off and retry.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Rate limit reached. Please retry after a short delay.
              type: rate_limit_error
              code: rate_limit_exceeded
              param: null
    InternalError:
      description: Temporary server error. Retry with backoff.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                The server had an error while processing your request. Please
                retry.
              type: api_error
              code: null
              param: null
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 'Your Deepshi API key, sent as `Authorization: Bearer <key>`.'

````