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

# Create images

> Make one to four pictures from a prompt with Z-Image Turbo, FLUX.2 Klein or Janus-Pro. Pictures come back as base64 PNG.

Makes one to four pictures from a prompt with one of the [picture models](https://docs.sharemy.ai/models.md#pictures). Each picture comes back as a base64-encoded PNG in `data[].b64_json`.

Send generation fields as JSON or multipart form data. To get a job id and poll for the pictures, send `Prefer: respond-async` or set `async` to `true`. See [Image jobs](https://docs.sharemy.ai/api-reference/jobs.md).

With `janus-pro-1b`, each picture is a separate job. If you request several and a later job fails, the API returns HTTP 200 with the pictures already made. Check `data.length` to see how many you received. If the first job fails, you get its HTTP error.

## Sizes

| Model | Sizes |
| - | - |
| `z-image-turbo` (default) | `256x256`, `512x512` (default), `1024x1024` |
| `flux2-klein` | `256x256`, `512x512` (default), `1024x1024` |
| `janus-pro-1b` | `384x384` only |

Any other size is refused with `400`, and the message lists the sizes the model takes.

## Seeds

`seed` is not part of OpenAI's API. With `z-image-turbo` and `flux2-klein`, the first picture uses `seed` and each further one uses the next number. Leave it out for a random seed. Each picture's seed comes back in `data[].seed`.

`janus-pro-1b` does not take a seed.

With the OpenAI Python SDK, send it with `extra_body={"seed": 42}`.

## Price

Each picture costs its model's price at its size, so `n` pictures cost `n` times as much. See [Credits and pricing](https://docs.sharemy.ai/credits-and-pricing.md#pictures).

## Differences from OpenAI

* **`response_format`:** only `b64_json`. `url` is refused.
* **`size`:** square sizes only, from the table above.
* **Ignored:** `quality`, `style`, `background`, `output_format`, `moderation`, `user`.
* **`revised_prompt`** is always `null`.
* For edits, upload a picture and mask to [Edit an image](https://docs.sharemy.ai/api-reference/image-edits.md). Image variations are unsupported.


## OpenAPI

````yaml api-reference/openapi.json POST /v1/images/generations
openapi: 3.1.0
info:
  title: ShareMyAI API
  version: 1.0.0
  description: >-
    OpenAI-shaped endpoints that run jobs on shared GPUs. Closing the connection
    cancels an unfinished synchronous job and returns its held credits. CORS
    allows any origin, echoes requested preflight headers and exposes Location,
    the request id, concurrency, retry, cost, balance, token cap and sample rate
    headers.
servers:
  - url: https://sharemy.ai
    description: ShareMyAI
security:
  - bearerAuth: []
tags:
  - name: Models
  - name: Chat
  - name: Images
  - name: Jobs
  - name: Audio
paths:
  /v1/images/generations:
    post:
      tags:
        - Images
      summary: Create images
      description: >-
        Make one to four pictures from a prompt. Pictures come back as
        base64-encoded PNG.
      operationId: createImage
      parameters:
        - name: Prefer
          in: header
          description: Send respond-async to receive a job id and poll for the result.
          schema:
            type: string
          example: respond-async
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageRequest'
            example:
              model: flux2-klein
              prompt: A lighthouse at dusk
              size: 512x512
              'n': 1
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ImageRequest'
      responses:
        '200':
          description: >-
            Generated pictures. A Janus request may return fewer than n if a
            later picture fails. The cost header totals completed pictures.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImagesResponse'
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            x-ratelimit-limit-concurrent:
              $ref: '#/components/headers/x-ratelimit-limit-concurrent'
            x-ratelimit-remaining-concurrent:
              $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
            X-ShareMyAI-Cost-Credits:
              $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
            X-ShareMyAI-Balance-Credits:
              $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        '202':
          $ref: '#/components/responses/JobAccepted'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '403':
          $ref: '#/components/responses/Suspended'
        '405':
          $ref: '#/components/responses/MethodNotAllowed'
        '429':
          $ref: '#/components/responses/TooManyCalls'
        '499':
          $ref: '#/components/responses/Cancelled'
        '502':
          $ref: '#/components/responses/NetworkError'
        '503':
          $ref: '#/components/responses/ImageUnavailable'
      x-codeSamples:
        - lang: bash
          label: curl
          source: |-
            curl https://sharemy.ai/v1/images/generations \
              -H "Authorization: Bearer $SHAREMYAI_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{"model": "flux2-klein", "prompt": "A lighthouse at dusk", "size": "512x512"}' \
              | jq -r '.data[0].b64_json' | base64 --decode > lighthouse.png
        - lang: python
          label: Python
          source: >-
            import base64, os

            from openai import OpenAI


            client = OpenAI(api_key=os.environ["SHAREMYAI_API_KEY"],
            base_url="https://sharemy.ai/v1")


            result = client.images.generate(
                model="flux2-klein",
                prompt="A lighthouse at dusk",
                size="512x512",
                extra_body={"seed": 42},  # optional; not part of OpenAI's API
            )

            with open("lighthouse.png", "wb") as f:
                f.write(base64.b64decode(result.data[0].b64_json))
        - lang: javascript
          label: Node
          source: >-
            import fs from "node:fs";

            import OpenAI from "openai";


            const client = new OpenAI({ apiKey: process.env.SHAREMYAI_API_KEY,
            baseURL: "https://sharemy.ai/v1" });


            const result = await client.images.generate({
              model: "flux2-klein",
              prompt: "A lighthouse at dusk",
              size: "512x512",
            });

            fs.writeFileSync("lighthouse.png",
            Buffer.from(result.data[0].b64_json, "base64"));
components:
  schemas:
    ImageRequest:
      type: object
      required:
        - prompt
      properties:
        model:
          type:
            - string
            - 'null'
          enum:
            - z-image-turbo
            - flux2-klein
            - janus-pro-1b
            - null
          default: z-image-turbo
        prompt:
          type: string
          minLength: 1
          maxLength: 2000
          description: What to draw, 1 to 2,000 characters.
        'n':
          type:
            - integer
            - 'null'
          minimum: 1
          maximum: 4
          default: 1
          description: >-
            Number of pictures requested. Janus returns completed pictures if a
            later job fails.
        size:
          type:
            - string
            - 'null'
          enum:
            - 256x256
            - 512x512
            - 1024x1024
            - 384x384
            - null
          description: >-
            `z-image-turbo` and `flux2-klein` take 256x256, 512x512 (their
            default) or 1024x1024. `janus-pro-1b` takes only 384x384, its
            default.
        response_format:
          type:
            - string
            - 'null'
          enum:
            - b64_json
            - null
          default: b64_json
          description: Only `b64_json`. There are no image URLs.
        seed:
          type:
            - integer
            - 'null'
          description: >-
            Not part of OpenAI's API. The seed for the first picture; each
            further picture uses the next number. Random when left out.
            `janus-pro-1b` does not use it.
        async:
          type:
            - boolean
            - string
            - 'null'
          description: >-
            A boolean true or the string "true" requests an async job. You can
            also send Prefer: respond-async.
      description: Top-level null fields are treated as omitted.
    ImagesResponse:
      type: object
      required:
        - created
        - data
      properties:
        created:
          type: integer
          description: Unix time in seconds.
        data:
          type: array
          items:
            type: object
            properties:
              b64_json:
                type: string
                description: A PNG file, base64-encoded.
              revised_prompt:
                type: 'null'
                description: 'Always null: prompts are used as sent.'
              seed:
                type:
                  - integer
                  - 'null'
                description: >-
                  The seed the picture was drawn with, when the model reports
                  one.
            required:
              - b64_json
              - revised_prompt
              - seed
    JobReceipt:
      type: object
      required:
        - id
        - object
        - created
        - endpoint
        - status
      properties:
        id:
          type: string
          description: Job id returned at submission.
        object:
          type: string
          const: job
        created:
          type: integer
          description: Unix time in seconds.
        endpoint:
          type: string
          enum:
            - /v1/images/generations
            - /v1/images/edits
        status:
          type: string
          const: queued
    Error:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
    ErrorDetail:
      type: object
      required:
        - message
        - type
        - param
        - code
      properties:
        message:
          type: string
          description: What went wrong, for a person to read.
        type:
          type: string
          description: >-
            402 uses insufficient_quota, other 4xx errors use
            invalid_request_error, and 5xx errors use api_error.
          enum:
            - invalid_request_error
            - insufficient_quota
            - api_error
        param:
          type:
            - string
            - 'null'
          description: The request field at fault, when there is one.
        code:
          type:
            - string
            - 'null'
          description: A stable code. The Errors and limits page lists them all.
          examples:
            - model_not_found
        price_credits:
          type: number
          description: Job price in credits on an insufficient_quota error.
        balance_credits:
          type: number
          description: Account balance in credits on an insufficient_quota error.
      if:
        properties:
          code:
            const: insufficient_quota
      then:
        required:
          - price_credits
          - balance_credits
  headers:
    x-request-id:
      description: Identifier for this API response.
      schema:
        type: string
    x-ratelimit-limit-concurrent:
      description: Job slots per account across all tokens.
      schema:
        type: integer
        const: 4
    x-ratelimit-remaining-concurrent:
      description: Free account slots when headers are sent.
      schema:
        type: integer
        minimum: 0
        maximum: 4
    X-ShareMyAI-Cost-Credits:
      description: >-
        Quoted price in credits when a job was accepted. For a Janus batch, the
        total for completed pictures.
      schema:
        type: number
    X-ShareMyAI-Balance-Credits:
      description: >-
        Balance in credits after the hold, from the last successful quote on a
        Janus batch.
      schema:
        type: number
    Retry-After:
      description: >-
        Seconds to wait. 2 on async submission and unfinished polls, 1 on a 429,
        and 30 on HTTP 503 no_provider.
      schema:
        type: integer
    X-ShareMyAI-Max-Tokens:
      description: Only on chat requests whose output budget was capped.
      schema:
        type: integer
        const: 4096
    x-should-retry:
      description: >-
        Suppress automatic retries for insufficient_quota,
        content_policy_violation or no_provider.
      schema:
        type: string
        const: 'false'
    Allow:
      description: Methods available for the requested path, including OPTIONS.
      schema:
        type: string
  responses:
    JobAccepted:
      description: >-
        Queued for background execution. Wait for Retry-After before polling
        Location.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/JobReceipt'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        Location:
          description: Relative path to poll with GET.
          schema:
            type: string
            format: uri-reference
        Retry-After:
          $ref: '#/components/headers/Retry-After'
    BadRequest:
      description: >-
        A field failed validation (invalid_value, model_not_found or
        unsupported_value), the body could not be read (null), a content check
        failed (content_policy_violation), or the job input was malformed
        (invalid_input).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Choose a temperature from 0 to 2.
              type: invalid_request_error
              param: temperature
              code: invalid_value
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
        x-should-retry:
          $ref: '#/components/headers/x-should-retry'
    Unauthorized:
      description: >-
        The message distinguishes a missing token, a key without the smai_
        prefix and an unknown or revoked ShareMyAI token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                Send your API token as Authorization: Bearer smai_…. Create one
                at https://sharemy.ai, account panel, API tokens.
              type: invalid_request_error
              param: null
              code: invalid_api_key
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
    InsufficientCredits:
      description: The balance is less than the job's price.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                This costs 8.192 credits and your balance is 3.000 credits. Add
                credits at https://sharemy.ai.
              type: insufficient_quota
              param: null
              code: insufficient_quota
              price_credits: 8.192
              balance_credits: 3
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
        x-should-retry:
          $ref: '#/components/headers/x-should-retry'
    Suspended:
      description: The account is suspended.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                This account is suspended. If you think that is a mistake,
                contact us.
              type: invalid_request_error
              param: null
              code: account_suspended
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
    MethodNotAllowed:
      description: The path exists. Use a method listed in Allow (method_not_allowed).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        Allow:
          $ref: '#/components/headers/Allow'
    TooManyCalls:
      description: >-
        Four job calls are already in flight across the account's tokens, or
        eligible machines stayed busy for 10 minutes. Both return
        rate_limit_exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: At most 4 API calls at once. Wait for one to finish.
              type: invalid_request_error
              param: null
              code: rate_limit_exceeded
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
    Cancelled:
      description: >-
        The caller hung up before the job finished. The job was dropped and its
        credits returned.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
    NetworkError:
      description: >-
        The job failed on the network, for example after three machines in turn
        left or stopped answering. Its credits were returned.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                The machine running this left the network. (request
                69ba81e5-6a67-4cd5-a28b-2e023337b936)
              type: api_error
              param: null
              code: network_error
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
    ImageUnavailable:
      description: >-
        no_provider when no eligible machine can run a synchronous job.
        storage_unavailable when async result storage is unavailable at
        submission. Retry-After and x-should-retry apply to no_provider.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        x-should-retry:
          $ref: '#/components/headers/x-should-retry'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        An API token from the account panel on sharemy.ai. Tokens start with
        `smai_`.

````

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