Skip to main content
POST
/
images
/
create
JavaScript
import Weights from '@weights-ai/sdk';

const client = new Weights({
  bearerToken: 'My Bearer Token',
});

const image = await client.images.create({
  prompt: 'A beautiful sunset over mountains with a lake in the foreground',
});

console.log(image.id);
{
  "id": "visual_123456789",
  "status": "SUCCEEDED",
  "prompt": "A beautiful sunset over mountains",
  "type": "IMAGE_GENERATION",
  "numImages": 1,
  "dimensions": "SQUARE",
  "createdAt": "2024-01-15T10:30:00Z",
  "updatedAt": "2024-01-15T10:35:00Z",
  "outputUrls": [
    "https://storage.example.com/images/generated_1.jpg"
  ],
  "lora": null,
  "secondaryLora": null
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
prompt
string
required

Text description of the image to generate

Required string length: 1 - 1000
Examples:

"A beautiful sunset over mountains with a lake in the foreground"

loraIds
string[]

Lora IDs to apply to the image generation - up to 3 Lora models can be applied

Maximum length: 3
Examples:
["cmcz8do7y00fw0dnd3t7906sy"]
numImages
number
default:1

Number of images to generate (1-4)

Required range: 1 <= x <= 4
Examples:

1

dimensions
enum<string>
default:SQUARE

Aspect ratio of the generated image

Available options:
SQUARE,
PORTRAIT,
LANDSCAPE
Examples:

"SQUARE"

Response

Returns the ID of the created image generation job.

id
string
required

Unique identifier for the visual creation job

Examples:

"visual_123456789"

status
enum<string>
required

Current status of the visual creation job

Available options:
QUEUED,
PENDING_WORKER,
PROCESSING,
ERRORED,
SUCCEEDED,
CANCELED
Examples:

"SUCCEEDED"

prompt
string
required

Text prompt used for the visual creation

Examples:

"A beautiful sunset over mountains"

type
enum<string>
required

Type of visual creation job

Available options:
IMAGE,
VIDEO,
EDIT,
REMIX,
INPAINT,
UPSCALE
Examples:

"IMAGE_GENERATION"

numImages
number
required

Number of images generated

Examples:

1

dimensions
enum<string>
required

Dimensions of the generated images

Available options:
SQUARE,
PORTRAIT,
LANDSCAPE
Examples:

"SQUARE"

createdAt
string
required

Timestamp when the job was created

Examples:

"2024-01-15T10:30:00Z"

updatedAt
string
required

Timestamp when the job was last updated

Examples:

"2024-01-15T10:35:00Z"

outputUrls
string[]
required

Array of URLs to the generated images

Examples:
[
"https://storage.example.com/images/generated_1.jpg"
]
lora
object | null
required

Primary LoRA model used for generation

Examples:

null

secondaryLora
object | null
required

Secondary LoRA model used for generation

Examples:

null

I