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

# Generate images

> Generates up to four images from a prompt and optional reference images, and returns them inline as base64.

Each image costs the model's micros_per_image, plus micros_per_reference for each reference image. Each image costs at least one credit. You pay only for the images delivered. If the request ends before the images return, you pay nothing.



## OpenAPI

````yaml /openapi.json post /v1/images/generations
openapi: 3.1.1
info:
  title: Morse API
  version: '1'
  description: >-
    The Morse API serves chat, image, web search, and page-reading models
    through an OpenAI-compatible interface. Each request pays with your Morse
    account's credits.


    Send an API key from the Morse app with every request, in the Authorization
    header as Bearer sk_morse_.... A key acts for its account and always pays
    with credits, never with a plan's included use. One credit is $0.01. GET
    /v1/models lists prices in micro-dollars, 10,000 to the credit. Keep keys on
    your server. Browsers on other sites cannot call the API.


    All of an account's keys and its owner's use of the Morse app share one
    budget of requests per minute and one limit on requests in flight. The
    account's plan sets both. A request refused for either limit carries
    Retry-After, the number of seconds to wait. A retried POST is a new request,
    and the API charges it again.


    An error reply is JSON in the Error shape, with a stable code. A path the
    API does not serve returns 404 as plain text, and a wrong method returns 405
    as plain text.
servers:
  - url: https://api.trymorse.ai
security:
  - apiKey: []
paths:
  /v1/images/generations:
    post:
      summary: Generate images
      description: >-
        Generates up to four images from a prompt and optional reference images,
        and returns them inline as base64.


        Each image costs the model's micros_per_image, plus micros_per_reference
        for each reference image. Each image costs at least one credit. You pay
        only for the images delivered. If the request ends before the images
        return, you pay nothing.
      operationId: createImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageRequest'
            example:
              model: flux-2-max
              prompt: a red apple on a wooden table, morning light
              'n': 2
              aspect_ratio: '16:9'
      responses:
        '200':
          description: The images.
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
            X-Funding:
              $ref: '#/components/headers/X-Funding'
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
              example:
                created: 1792187825
                data:
                  - b64_json: iVBORw0KGgoAAAANSUhEUgAA...
                    mime_type: image/png
                  - b64_json: iVBORw0KGgoAAAANSUhEUgAA...
                    mime_type: image/png
        '400':
          description: The request is malformed, or the model or its provider refused it.
          x-error-codes:
            - code: invalid_request_body
              when: >-
                The body is not a JSON object, a field has the wrong JSON type,
                or model is missing.
            - code: invalid_parameter
              when: >-
                A field has a value the endpoint refuses. The message names the
                field.
            - code: duplicate_json_key
              when: A JSON object in the body repeats a key.
            - code: remote_media
              when: 'A reference image links a URL instead of a data: URL.'
            - code: content_filter
              when: The provider declined the prompt.
            - code: invalid_request
              when: The provider rejected the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: n must be between 1 and 4.
                  type: invalid_request_error
                  param: null
                  code: invalid_parameter
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
        '401':
          description: The key is missing or wrong.
          x-error-codes:
            - code: invalid_api_key
              when: >-
                The Authorization header is missing or not Bearer, the key is
                unknown or revoked, or a token that starts with sk_ is not a
                whole sk_morse_ key.
            - code: invalid_token
              when: >-
                The bearer token is not a Morse API key. Send the whole
                sk_morse_ key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Incorrect API key provided.
                  type: invalid_request_error
                  param: null
                  code: invalid_api_key
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
        '402':
          description: The account's credits do not cover the request.
          x-error-codes:
            - code: insufficient_balance
              when: >-
                The balance is below the amount the request must hold. While the
                balance is negative, the API refuses every metered request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    The account balance does not cover the most this request
                    could cost. Add credit, or ask for fewer images or reference
                    images.
                  type: insufficient_balance
                  param: null
                  code: insufficient_balance
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
        '403':
          description: The key's account may not make this request.
          x-error-codes:
            - code: account_disabled
              when: Morse has disabled the key's account.
            - code: account_deleted
              when: The key's account has been deleted.
            - code: account_under_18
              when: The account's owner said they are under 18.
            - code: model_requires_plan
              when: >-
                The model needs a higher plan than the account's, even when
                credits pay for the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: This account has been disabled. Contact support.
                  type: invalid_request_error
                  param: null
                  code: account_disabled
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
        '404':
          description: The model does not exist, or it is not a model for this endpoint.
          x-error-codes:
            - code: model_not_found
              when: No model of this endpoint's type has that name.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: The requested model does not exist.
                  type: invalid_request_error
                  param: null
                  code: model_not_found
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
        '408':
          description: The request body arrived too slowly.
          x-error-codes:
            - code: request_timeout
              when: The request body did not arrive within one minute.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: The request body did not arrive in time.
                  type: invalid_request_error
                  param: null
                  code: request_timeout
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
        '413':
          description: The request body is too large.
          x-error-codes:
            - code: request_too_large
              when: The body is over 32 MiB, or too large for the provider.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Request body is too large.
                  type: invalid_request_error
                  param: null
                  code: request_too_large
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
        '429':
          description: >-
            The account is over its rate limit or its concurrency limit. Wait
            the number of seconds in Retry-After, then retry.
          x-error-codes:
            - code: rate_limit_exceeded
              when: >-
                The account used up its requests per minute. All of the
                account's keys and its owner's use of the Morse app share one
                budget.
            - code: concurrency_limit_exceeded
              when: >-
                The account already has its maximum number of requests in
                flight. Retry-After is 1.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    Rate limit reached for this account. Retry after the time in
                    the Retry-After header.
                  type: requests
                  param: null
                  code: rate_limit_exceeded
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
            Retry-After:
              $ref: '#/components/headers/Retry-After'
        '502':
          description: The image provider failed.
          x-error-codes:
            - code: upstream_error
              when: >-
                The provider failed, returned no images, or took more than 10
                minutes.
            - code: upstream_unavailable
              when: >-
                The provider is unavailable right now. Retry later, or choose
                another model.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: The upstream model server failed.
                  type: upstream_error
                  param: null
                  code: upstream_error
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
        '503':
          description: >-
            Morse or the provider is busy or unavailable. Retry the request
            later.
          x-error-codes:
            - code: service_unavailable
              when: Morse could not start the request. Retry it.
            - code: server_busy
              when: Morse is busy. Retry-After is 1.
            - code: upstream_busy
              when: The provider is overloaded. Try again shortly.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: >-
                    The service is temporarily unable to authorize requests. Try
                    again shortly.
                  type: server_error
                  param: null
                  code: service_unavailable
          headers:
            X-Morse-Version:
              $ref: '#/components/headers/X-Morse-Version'
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
            Retry-After:
              $ref: '#/components/headers/Retry-After'
components:
  schemas:
    ImageRequest:
      type: object
      required:
        - model
        - prompt
      additionalProperties: false
      description: >-
        Morse refuses any field not listed here, such as size, style, or user,
        with invalid_parameter.
      properties:
        model:
          type: string
          description: An image model's id from GET /v1/models.
        prompt:
          type: string
          minLength: 1
        'n':
          type: integer
          minimum: 1
          maximum: 4
          default: 1
        aspect_ratio:
          type: string
          enum:
            - '1:1'
            - '16:9'
            - '9:16'
            - '4:3'
            - '3:4'
            - '3:2'
            - '2:3'
          description: >-
            Defaults to 1:1. With reference images, it defaults to the ratio
            nearest the first reference image's.
        resolution:
          type: string
          enum:
            - 1k
            - 2k
          default: 1k
          description: Some models take 1k only.
        quality:
          type: string
          description: >-
            Applies only to models with a quality setting. Values include low,
            medium, and high.
        response_format:
          const: b64_json
          description: Images always come back inline.
        images:
          type: array
          items:
            type: string
          description: >-
            Reference images, as base64 data URLs of PNG, JPEG, or WebP images.
            Each model sets its own maximum, and some models take none. Each
            reference image adds to the price of every image.
    ImageResponse:
      type: object
      required:
        - created
        - data
      properties:
        created:
          type: integer
          description: Unix seconds.
        data:
          type: array
          description: >-
            The images. If the provider returned fewer than n, data holds fewer,
            and you pay only for the images delivered.
          items:
            type: object
            required:
              - b64_json
              - mime_type
            properties:
              b64_json:
                type: string
                description: The image, base64-encoded, with its metadata stripped.
              mime_type:
                type: string
                enum:
                  - image/png
                  - image/jpeg
                  - image/webp
    Error:
      type: object
      description: >-
        Every JSON error reply has this shape. Branch on code, which is stable.
        The message is for people and can change.
      additionalProperties: false
      required:
        - error
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - message
            - type
            - param
            - code
          properties:
            message:
              type: string
              description: A sentence that says what went wrong and what to do.
            type:
              type: string
              description: >-
                The error's family, such as invalid_request_error,
                insufficient_balance, plan, requests, upstream_error, or
                server_error. plan means the account's plan does not allow the
                model, even when credits pay for the request.
            param:
              type:
                - string
                - 'null'
              description: Always null on the endpoints documented here.
            code:
              type: string
              description: >-
                The specific error. Each operation lists the codes it can
                return.
  headers:
    X-Morse-Version:
      description: The running build. Every reply carries it.
      schema:
        type: string
    X-Funding:
      description: >-
        What pays for the request. With a key, the value is always credits. A
        request that Morse refuses before it bills anything has no X-Funding.
      schema:
        type: string
        enum:
          - credits
          - included
    X-Request-Id:
      description: >-
        An id for this request. Quote it when you contact support about the
        request. An error that arrives after the request starts carries it too.
        A request that Morse refuses before it bills anything has no
        X-Request-Id.
      schema:
        type: string
    Retry-After:
      description: Whole seconds to wait before retrying, at least 1.
      schema:
        type: integer
        minimum: 1
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: sk_morse_...
      description: An API key from the Morse app. It starts with sk_morse_.

````

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