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

# Generate images

> <Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Generates up to four images from a prompt, optionally guided by reference images, and stores them in the app's files. Returns their URLs. Billed to the app's credits at the same price as an AI gateway call.

For an estimate that generates and charges nothing, send the body you plan to generate with and add `dry_run: true`. The price depends on the model and the length, so an estimate for a different body can be off. Send an `Idempotency-Key` with each generation, and the same key when you retry it, so a retry isn't charged twice.

When the model provider fails, the same request usually fails the same way again, so try another model rather than resending it unchanged.



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json post /api/apps/{app_id}/media/images
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/media/images:
    post:
      summary: Generate images
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Generates up to four images from a prompt, optionally guided by
        reference images, and stores them in the app's files. Returns their
        URLs. Billed to the app's credits at the same price as an AI gateway
        call.


        For an estimate that generates and charges nothing, send the body you
        plan to generate with and add `dry_run: true`. The price depends on the
        model and the length, so an estimate for a different body can be off.
        Send an `Idempotency-Key` with each generation, and the same key when
        you retry it, so a retry isn't charged twice.


        When the model provider fails, the same request usually fails the same
        way again, so try another model rather than resending it unchanged.
      operationId: create_images_api_apps__app_id__media_images_post
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the app to generate media for.
            title: App Id
          description: ID of the app to generate media for.
          example: 6820f3a4e7b91d003c45a1f2
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            description: >-
              One key per operation, 1 to 128 characters. A retry with the same
              key and request within 24 hours returns the first response.
            examples:
              - 7f3c9a2e-retry-1
            title: Idempotency-Key
          description: >-
            One key per operation, 1 to 128 characters. A retry with the same
            key and request within 24 hours returns the first response.
        - name: X-Active-Branch-Id
          in: header
          required: false
          schema:
            type: string
            description: >-
              ID of the branch the editor shows. Used when `branch_id` is
              omitted, for users who work on protected-main branches.
            title: X-Active-Branch-Id
          description: >-
            ID of the branch the editor shows. Used when `branch_id` is omitted,
            for users who work on protected-main branches.
          example: 68f1a2b3c4d5e6f708192a3b
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateImagesRequest'
      responses:
        '200':
          description: The stored images, or an estimate for a dry run.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/ImagesResponse'
                  - $ref: '#/components/schemas/Estimate'
                title: Response Create Images Api Apps  App Id  Media Images Post
              example:
                images:
                  - url: https://media.base44.com/images/public/6820f3a4/logo.png
                usage:
                  credits: 4
        '400':
          description: >-
            The request can't be served (`invalid_request_error`,
            `model_not_found`), for example an option the model doesn't support.
            `details.param` names the field.
          content:
            application/json:
              examples:
                invalid_request_error:
                  summary: invalid_request_error
                  value:
                    error:
                      code: invalid_request_error
                      message: '`n` must be between 1 and 4.'
                      details:
                        param: 'n'
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '402':
          description: >-
            The app's workspace doesn't have enough credits
            (`insufficient_quota`).
          content:
            application/json:
              examples:
                insufficient_quota:
                  summary: insufficient_quota
                  value:
                    error:
                      code: insufficient_quota
                      message: Not enough credits.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '403':
          description: >-
            The workspace's AI policy turns off media generation for this app
            (`forbidden`).
          content:
            application/json:
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    error:
                      code: forbidden
                      message: AI media generation is turned off for this app.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '404':
          description: >-
            The API isn't enabled for you, or the app doesn't exist or you can't
            edit it (`not_found`).
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    error:
                      code: not_found
                      message: Not found.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '409':
          description: >-
            `idempotency_in_progress`: A request with this `Idempotency-Key` is
            still running, or its outcome isn't known yet.
          content:
            application/json:
              examples:
                idempotency_in_progress:
                  summary: idempotency_in_progress
                  value:
                    error:
                      code: idempotency_in_progress
                      message: >-
                        A request with this Idempotency-Key is still running.
                        Retry shortly.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '422':
          description: >-
            The request body is invalid (`detail`). `idempotency_key_reused`:
            The `Idempotency-Key` was already used with a different request.
            `invalid_request`: The `Idempotency-Key` header is empty or longer
            than 128 characters.
          content:
            application/json:
              examples:
                idempotency_key_reused:
                  summary: idempotency_key_reused
                  value:
                    error:
                      code: idempotency_key_reused
                      message: >-
                        This Idempotency-Key was already used with a different
                        request.
                      details: {}
                invalid_request:
                  summary: invalid_request
                  value:
                    error:
                      code: invalid_request
                      message: Idempotency-Key must be 1 to 128 characters.
                      details: {}
              schema:
                anyOf:
                  - $ref: '#/components/schemas/HTTPValidationError'
                  - $ref: '#/components/schemas/StandardErrorEnvelope'
        '429':
          description: >-
            Too many requests (`rate_limited`). The base limit is 20 requests
            per 60 seconds for each caller, raised by your plan's multiplier.
            Retry after the `Retry-After` seconds.
          content:
            application/json:
              examples:
                rate_limited:
                  summary: rate_limited
                  value:
                    error:
                      code: rate_limited
                      message: Rate limit exceeded.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '502':
          description: >-
            The model provider or file storage couldn't complete the request
            (`internal_error`).
          content:
            application/json:
              examples:
                internal_error:
                  summary: internal_error
                  value:
                    error:
                      code: internal_error
                      message: Internal server error
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '503':
          description: >-
            Database temporarily unavailable (`database_unavailable`): the data
            cluster did not answer in time. Retry after the `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
              examples:
                database_unavailable:
                  summary: database_unavailable
                  value:
                    error:
                      code: database_unavailable
                      message: Database temporarily unavailable, please retry
                      details: {}
      security:
        - PersonalAccessTokenAuth:
            - full_access
        - WorkspaceApiKeyAuth:
            - full_access
        - WorkspaceApiKeyBearerAuth:
            - full_access
components:
  schemas:
    CreateImagesRequest:
      properties:
        dry_run:
          type: boolean
          title: Dry Run
          description: >-
            `true` returns a credit estimate without generating or charging;
            omit or `false` to generate
          default: false
        model:
          anyOf:
            - type: string
              maxLength: 100
            - type: 'null'
          title: Model
          description: >-
            prefer `"automatic"`, which selects a model that supports every
            requested control together
          examples:
            - automatic
        prompt:
          type: string
          maxLength: 32000
          minLength: 1
          title: Prompt
          description: required; image instructions
          examples:
            - A flat logo of a fox
        reference_image_urls:
          items:
            type: string
          type: array
          maxItems: 16
          title: Reference Image Urls
          description: >-
            Public HTTPS image URLs, or this app's own files, that guide the
            output.
        aspect_ratio:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Aspect Ratio
          description: output proportions, such as `16:9`
          examples:
            - '16:9'
        resolution:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Resolution
          description: output pixel scale, such as `1K`
        size:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Size
          description: >-
            OpenAI pixel size such as `1024x1024`; prefer `aspect_ratio` and
            `resolution`
          examples:
            - 1024x1024
        'n':
          anyOf:
            - type: integer
              maximum: 4
              minimum: 1
            - type: 'null'
          title: 'N'
          description: output count
        quality:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Quality
          description: rendering quality
        output_format:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Output Format
          description: image file encoding
        background:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Background
          description: '`transparent` or `opaque` output background'
      additionalProperties: false
      type: object
      required:
        - prompt
      title: CreateImagesRequest
    ImagesResponse:
      properties:
        images:
          items:
            $ref: '#/components/schemas/GeneratedImage'
          type: array
          title: Images
        usage:
          $ref: '#/components/schemas/MediaUsage'
      type: object
      required:
        - images
        - usage
      title: ImagesResponse
    Estimate:
      properties:
        dry_run:
          type: boolean
          const: true
          title: Dry Run
          description: 'Always `true`: nothing was generated or charged.'
        model:
          type: string
          title: Model
          description: The model that would serve the request.
          examples:
            - gpt_image_2
        usage:
          $ref: '#/components/schemas/MediaUsage'
      type: object
      required:
        - dry_run
        - model
        - usage
      title: Estimate
    StandardErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/StandardError'
          description: What went wrong.
      type: object
      required:
        - error
      title: StandardErrorEnvelope
      description: The error body returned in the standard envelope.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    GeneratedImage:
      properties:
        url:
          type: string
          title: Url
          description: >-
            Public URL of the stored image. Anyone with the link can open it,
            and the link doesn't expire.
      type: object
      required:
        - url
      title: GeneratedImage
    MediaUsage:
      properties:
        credits:
          type: number
          title: Credits
          description: Credits charged to the app, or the estimate for a dry run.
          examples:
            - 4
      type: object
      required:
        - credits
      title: MediaUsage
    StandardError:
      properties:
        code:
          type: string
          title: Code
          description: >-
            Stable machine-readable cause of the failure. Match on this, not on
            `message`.
          example: not_found
        message:
          type: string
          title: Message
          description: Human-readable explanation. It isn't a stable contract.
          example: App not found
        details:
          additionalProperties: true
          type: object
          title: Details
          description: >-
            Structured context for the failure, or an empty object when there's
            none.
          example: {}
      type: object
      required:
        - code
        - message
      title: StandardError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.
    WorkspaceApiKeyAuth:
      type: apiKey
      in: header
      name: api_key
      description: >-
        Workspace API key, sent as `api_key: <key>`. Each operation that accepts
        one lists what the key needs: a permission, `read_only` or
        `full_access`, like a personal access token, or a scope. A key without
        the scope gets 403 `workspace_api_key_scope_required`.
    WorkspaceApiKeyBearerAuth:
      type: http
      scheme: bearer
      description: >-
        Workspace API key, sent as `Authorization: Bearer <key>`. Accepted
        wherever `api_key` is, with the same permission.

````

## Related topics

- [Generate images with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-images.md)
- [Generate music with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-music.md)
- [Generate video with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-video.md)
- [Using Base44 built-in integrations](https://docs.base44.com/Integrations/built-in-integrations.md)
- [Credits](https://docs.base44.com/Account-and-billing/Credits.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.