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

# Opprett et Runway-bilde

> Generer bilder med Gen-4 Image eller Gen-4 Image Turbo ved hjelp av tekst og referansebilder.

Bruk dette endepunktet til å generere et bilde fra en Prompt, med valgfrie referanse
bilder for `gen4_image`. Send CometAPI API-nøkkelen din med Bearer-autentisering
og en JSON-forespørselstekst.

## Velg en modell og referanser

Hver forespørsel krever `model`, `promptText` og `ratio`.

| Modell             | `referenceImages`                                                                                      |
| ------------------ | ------------------------------------------------------------------------------------------------------ |
| `gen4_image`       | Valgfritt. Utelat feltet eller bruk `[]` for generering med bare tekst, eller oppgi opptil tre bilder. |
| `gen4_image_turbo` | Oppgi ett til tre bilder.                                                                              |

For `gen4_image_turbo` er `referenceImages` obligatorisk og må inneholde ett til
tre bilder. Hvert referanseobjekt inneholder en bilde-`uri` og en valgfri
`tag`. Bruk en tagg på 3 til 16 små bokstaver,
sifre eller understreker, og den må starte med en bokstav. Referer til den i `promptText`
som `@tag`, for eksempel `@cat_ref`.

Bilde-URI-er godtar tilgjengelige HTTPS-URL-er eller Base64-data-URI-er for bilder på opptil
5 MB. Prompt godtar 1 til 1 000 UTF-16-kodeenheter.

## Velg dimensjoner

Angi `ratio` til ett av de nøyaktige dimensjonsparene i skjemaet. For eksempel
`1024:1024` ber `1280:720` om et kvadratisk bilde, et liggende bilde, og
`720:1280` et stående bilde. Bruk `ratio` for å velge dimensjoner; ikke send
`resolution` eller `size` med disse modellene.

For en eksplisitt seed for sampling bruker du `1` til `4294967295`. Utelatelse eller `0`
velger en tilfeldig seed. Hvis du inkluderer `contentModeration`, angir du dens
`publicFigureThreshold` til `auto` eller `low`; ellers utelater du objektet.

## Hent resultatet

Lagre den returnerte `id` og bruk [Hent en Runway-oppgave](./runway-to-get-task-details).
Når `status` er `SUCCEEDED`, leser du de genererte bilde-URL-ene i `output`.


## OpenAPI

````yaml api/openapi/video/runway/official-format/post-generate-an-image-from-text.openapi.json POST /runwayml/v1/text_to_image
openapi: 3.1.0
info:
  title: Create a Runway image
  version: 1.0.0
  description: Create a Runway image through CometAPI.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /runwayml/v1/text_to_image:
    post:
      summary: Create a Runway image
      description: >-
        Submit a JSON request and save the returned id. Use GET
        /runwayml/v1/tasks/{id} to retrieve the result.
      operationId: generate_an_image_from_text
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - title: gen4_image
                  type: object
                  properties:
                    model:
                      type: string
                      description: Model ID for this request variant.
                      const: gen4_image
                      enum:
                        - gen4_image
                    promptText:
                      description: >-
                        Describe the requested scene or motion in 1 to 1,000
                        UTF-16 code units.
                      type: string
                      minLength: 1
                      maxLength: 1000
                    seed:
                      type: integer
                      minimum: 0
                      maximum: 4294967295
                      description: >-
                        Optional sampling seed. Use a positive integer for an
                        explicit seed. Omission or 0 selects a random seed.
                    ratio:
                      description: >-
                        Requested output dimensions, expressed as width:height.
                        Choose a value listed for this model and endpoint.
                      type: string
                      enum:
                        - '1024:1024'
                        - '1080:1080'
                        - '1168:880'
                        - '1360:768'
                        - '1440:1080'
                        - '1080:1440'
                        - '1808:768'
                        - '1920:1080'
                        - '1080:1920'
                        - '2112:912'
                        - '1280:720'
                        - '720:1280'
                        - '720:720'
                        - '960:720'
                        - '720:960'
                        - '1680:720'
                    referenceImages:
                      description: >-
                        Optional array of up to three reference images. Omit it
                        or use an empty array for text-only generation.
                      maxItems: 3
                      type: array
                      items:
                        type: object
                        properties:
                          uri:
                            description: >-
                              Source image as a public HTTPS URL or a Base64
                              image data URI.
                            oneOf:
                              - type: string
                                description: >-
                                  Public HTTPS image URL. The server must allow
                                  HEAD and GET without redirects.
                                pattern: ^https://
                                maxLength: 2048
                              - type: string
                                description: >-
                                  Base64 image data URI, including its media
                                  type. Maximum encoded length: 5 MB.
                                pattern: ^data:image/[^;]+;base64,
                                maxLength: 5242880
                          tag:
                            type: string
                            description: >-
                              Optional lowercase reference label. Refer to it as
                              @tag in promptText.
                            minLength: 3
                            maxLength: 16
                            pattern: ^[a-z][a-z0-9_]+$
                        required:
                          - uri
                        additionalProperties: false
                      minItems: 0
                    contentModeration:
                      type: object
                      description: >-
                        Optional content moderation settings. Omit the object to
                        use standard moderation.
                      properties:
                        publicFigureThreshold:
                          type: string
                          description: >-
                            Use auto for standard moderation or low for less
                            restrictive public-figure filtering.
                          enum:
                            - auto
                            - low
                      required:
                        - publicFigureThreshold
                      additionalProperties: false
                  required:
                    - promptText
                    - ratio
                    - model
                  additionalProperties: false
                  description: Request parameters for gen4_image.
                - title: gen4_image_turbo
                  type: object
                  properties:
                    model:
                      type: string
                      description: Model ID for this request variant.
                      const: gen4_image_turbo
                      enum:
                        - gen4_image_turbo
                    promptText:
                      description: >-
                        Describe the requested scene or motion in 1 to 1,000
                        UTF-16 code units.
                      type: string
                      minLength: 1
                      maxLength: 1000
                    seed:
                      type: integer
                      minimum: 0
                      maximum: 4294967295
                      description: >-
                        Optional sampling seed. Use a positive integer for an
                        explicit seed. Omission or 0 selects a random seed.
                    ratio:
                      description: >-
                        Requested output dimensions, expressed as width:height.
                        Choose a value listed for this model and endpoint.
                      type: string
                      enum:
                        - '1024:1024'
                        - '1080:1080'
                        - '1168:880'
                        - '1360:768'
                        - '1440:1080'
                        - '1080:1440'
                        - '1808:768'
                        - '1920:1080'
                        - '1080:1920'
                        - '2112:912'
                        - '1280:720'
                        - '720:1280'
                        - '720:720'
                        - '960:720'
                        - '720:960'
                        - '1680:720'
                    referenceImages:
                      description: >-
                        One to three reference images. An empty array, null, or
                        an omitted field is not a valid request for this model.
                      minItems: 1
                      maxItems: 3
                      type: array
                      items:
                        type: object
                        properties:
                          uri:
                            description: >-
                              Source image as a public HTTPS URL or a Base64
                              image data URI.
                            oneOf:
                              - type: string
                                description: >-
                                  Public HTTPS image URL. The server must allow
                                  HEAD and GET without redirects.
                                pattern: ^https://
                                maxLength: 2048
                              - type: string
                                description: >-
                                  Base64 image data URI, including its media
                                  type. Maximum encoded length: 5 MB.
                                pattern: ^data:image/[^;]+;base64,
                                maxLength: 5242880
                          tag:
                            type: string
                            description: >-
                              Optional lowercase reference label. Refer to it as
                              @tag in promptText.
                            minLength: 3
                            maxLength: 16
                            pattern: ^[a-z][a-z0-9_]+$
                        required:
                          - uri
                        additionalProperties: false
                    contentModeration:
                      type: object
                      description: >-
                        Optional content moderation settings. Omit the object to
                        use standard moderation.
                      properties:
                        publicFigureThreshold:
                          type: string
                          description: >-
                            Use auto for standard moderation or low for less
                            restrictive public-figure filtering.
                          enum:
                            - auto
                            - low
                      required:
                        - publicFigureThreshold
                      additionalProperties: false
                  required:
                    - promptText
                    - ratio
                    - referenceImages
                    - model
                  additionalProperties: false
                  description: Request parameters for gen4_image_turbo.
              discriminator:
                propertyName: model
            examples:
              Gen-4 Image with a reference:
                summary: Gen-4 Image with a reference
                value:
                  model: gen4_image
                  promptText: A watercolor portrait of @cat_ref.
                  ratio: '1024:1024'
                  referenceImages:
                    - uri: >-
                        https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg
                      tag: cat_ref
              Gen-4 Image from text:
                summary: Gen-4 Image from text
                value:
                  model: gen4_image
                  promptText: A paper boat on calm water at sunrise.
                  ratio: '1024:1024'
              Gen-4 Image Turbo:
                summary: Gen-4 Image Turbo
                value:
                  model: gen4_image_turbo
                  promptText: A watercolor portrait of @cat_ref.
                  ratio: '1024:1024'
                  referenceImages:
                    - uri: >-
                        https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg
                      tag: cat_ref
      responses:
        '200':
          description: Task submitted. Save its id to retrieve task status.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: Task ID for GET /runwayml/v1/tasks/{id}.
                  status:
                    type: string
                    description: Task state, when returned.
                  createdAt:
                    type: string
                    description: Task submission timestamp, when returned.
                    format: date-time
                  output:
                    type: array
                    description: Result URLs, when returned.
                    items:
                      type: string
                      format: uri
                  failure:
                    type: string
                    description: Failure explanation, when returned.
                  failureCode:
                    type: string
                    description: Machine-readable failure code, when returned.
                  estimatedCost:
                    type: object
                    description: Task estimate metadata, when returned.
                    properties:
                      credits:
                        type: integer
                        description: Credit value reported with the task.
                    required:
                      - credits
                    additionalProperties: false
                  cost:
                    type: object
                    description: Task cost metadata, when returned.
                    properties:
                      credits:
                        type: integer
                        description: Credit value reported with the task.
                    required:
                      - credits
                    additionalProperties: false
                required:
                  - id
                additionalProperties: false
              example:
                id: 00000000-0000-4000-8000-000000000001
        '400':
          description: Invalid request or unavailable task ID.
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    description: Task request error.
                    properties:
                      code:
                        type:
                          - string
                          - integer
                        description: Machine-readable task error code.
                      message:
                        type: string
                        description: Error explanation.
                      data:
                        description: Additional error details, when returned.
                    required:
                      - code
                      - message
                    additionalProperties: true
                  - type: object
                    description: Request authentication or validation error.
                    properties:
                      error:
                        type: object
                        description: Error details.
                        properties:
                          message:
                            type: string
                            description: Error explanation.
                          type:
                            type: string
                            description: Error category.
                          code:
                            type:
                              - string
                              - integer
                              - 'null'
                            description: Error code, when returned.
                        required:
                          - message
                        additionalProperties: true
                    required:
                      - error
                    additionalProperties: true
        '401':
          description: Authentication failed.
          content:
            application/json:
              schema:
                type: object
                description: Request authentication or validation error.
                properties:
                  error:
                    type: object
                    description: Error details.
                    properties:
                      message:
                        type: string
                        description: Error explanation.
                      type:
                        type: string
                        description: Error category.
                      code:
                        type:
                          - string
                          - integer
                          - 'null'
                        description: Error code, when returned.
                    required:
                      - message
                    additionalProperties: true
                required:
                  - error
                additionalProperties: true
      x-codeSamples:
        - lang: Shell
          label: Gen-4 Image with a reference
          source: |
            curl "https://api.cometapi.com/runwayml/v1/text_to_image" \
              --request POST \
              --header "Authorization: Bearer $COMETAPI_KEY" \
              --header "Content-Type: application/json" \
              --data '{
              "model": "gen4_image",
              "promptText": "A watercolor portrait of @cat_ref.",
              "ratio": "1024:1024",
              "referenceImages": [
                {
                  "uri": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg",
                  "tag": "cat_ref"
                }
              ]
            }'
        - lang: Python
          label: Gen-4 Image with a reference
          source: |
            import os
            import requests

            payload = {'model': 'gen4_image',
             'promptText': 'A watercolor portrait of @cat_ref.',
             'ratio': '1024:1024',
             'referenceImages': [{'uri': 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg',
                                  'tag': 'cat_ref'}]}

            response = requests.post(
                "https://api.cometapi.com/runwayml/v1/text_to_image",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json=payload,
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Gen-4 Image with a reference
          source: |
            const payload = {
              "model": "gen4_image",
              "promptText": "A watercolor portrait of @cat_ref.",
              "ratio": "1024:1024",
              "referenceImages": [
                {
                  "uri": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg",
                  "tag": "cat_ref"
                }
              ]
            };

            const response = await fetch(
              "https://api.cometapi.com/runwayml/v1/text_to_image",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );
            if (!response.ok) throw new Error(await response.text());
            console.log((await response.json()).id);
        - lang: Shell
          label: Gen-4 Image from text
          source: |
            curl "https://api.cometapi.com/runwayml/v1/text_to_image" \
              --request POST \
              --header "Authorization: Bearer $COMETAPI_KEY" \
              --header "Content-Type: application/json" \
              --data '{
              "model": "gen4_image",
              "promptText": "A paper boat on calm water at sunrise.",
              "ratio": "1024:1024"
            }'
        - lang: Python
          label: Gen-4 Image from text
          source: |
            import os
            import requests

            payload = {'model': 'gen4_image',
             'promptText': 'A paper boat on calm water at sunrise.',
             'ratio': '1024:1024'}

            response = requests.post(
                "https://api.cometapi.com/runwayml/v1/text_to_image",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json=payload,
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Gen-4 Image from text
          source: |
            const payload = {
              "model": "gen4_image",
              "promptText": "A paper boat on calm water at sunrise.",
              "ratio": "1024:1024"
            };

            const response = await fetch(
              "https://api.cometapi.com/runwayml/v1/text_to_image",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );
            if (!response.ok) throw new Error(await response.text());
            console.log((await response.json()).id);
        - lang: Shell
          label: Gen-4 Image Turbo
          source: |
            curl "https://api.cometapi.com/runwayml/v1/text_to_image" \
              --request POST \
              --header "Authorization: Bearer $COMETAPI_KEY" \
              --header "Content-Type: application/json" \
              --data '{
              "model": "gen4_image_turbo",
              "promptText": "A watercolor portrait of @cat_ref.",
              "ratio": "1024:1024",
              "referenceImages": [
                {
                  "uri": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg",
                  "tag": "cat_ref"
                }
              ]
            }'
        - lang: Python
          label: Gen-4 Image Turbo
          source: |
            import os
            import requests

            payload = {'model': 'gen4_image_turbo',
             'promptText': 'A watercolor portrait of @cat_ref.',
             'ratio': '1024:1024',
             'referenceImages': [{'uri': 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg',
                                  'tag': 'cat_ref'}]}

            response = requests.post(
                "https://api.cometapi.com/runwayml/v1/text_to_image",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json=payload,
                timeout=60,
            )
            response.raise_for_status()
            print(response.json()["id"])
        - lang: JavaScript
          label: Gen-4 Image Turbo
          source: |
            const payload = {
              "model": "gen4_image_turbo",
              "promptText": "A watercolor portrait of @cat_ref.",
              "ratio": "1024:1024",
              "referenceImages": [
                {
                  "uri": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg",
                  "tag": "cat_ref"
                }
              ]
            };

            const response = await fetch(
              "https://api.cometapi.com/runwayml/v1/text_to_image",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );
            if (!response.ok) throw new Error(await response.text());
            console.log((await response.json()).id);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Use your CometAPI API key.

````