# Generate image

Generate an image from a prompt using workspace credits. Returns a temporary URL accessible to the caller. If generation is still running, retry with the same request ID to collect the result.

POST https://api.brigg.app/v1/operations/images.GenerateImage

## Access & visibility

Allow `images.GenerateImage` on your API key.

**Acting member required.** Send `Brigg-Act-As` with an [approved member account ID](https://developer.brigg.app/authentication#member-delegation). The key supplies permissions; the member selects whose data is used.

The selected member must be active and approved by the credential. This selects whose private data is used; the credential supplies permissions. Private ownership and project boundaries still apply.

[Set up authentication](https://developer.brigg.app/authentication) · [Choose permissions](https://developer.brigg.app/permissions)

## Request fields

Send a JSON object with the following fields. Required fields must be included; omit optional fields you do not need.
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `prompt` | string | Yes | What to draw. No words inside the image. At least 1 character. At most 4000 characters. |
| `aspect_ratio` | string | No | Requested image proportions, using one of the supported values. Allowed: `"1:1"`, `"2:3"`, `"3:2"`, `"3:4"`, `"4:3"`, `"4:5"`, `"5:4"`, `"9:16"`, `"16:9"`, `"21:9"`. |
| `size` | string | No | Resolution; 1K when omitted. Bigger costs the org more. Allowed: `"1K"`, `"2K"`, `"4K"`. |
| `reference_files` | array of [object](#request-reference-files) | No | Pictures that steer the generation — a product photo to keep faithful, a sketch, a style to follow. Pictures only, never a document. At most 3 items. |

### request.reference_files[]

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Display name. At least 1 character. At most 120 characters. |
| `media_type` | string | Yes | image/png, image/jpeg, image/gif or image/webp. At least 1 character. |
| `data` | string | Yes | The bytes, base64. At least 1 character. |

## Response

Returns **200 OK** with a JSON body.
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | string | Yes | A short-lived, caller-private download URL for the bytes. |
| `ext` | string | Yes | png / jpg / … from the bytes. |
| `bytes` | number | No | Size of the generated image in bytes. |

## Errors & retries

Set `BRIGG_REQUEST_ID` once for each logical action. The samples send it as `Idempotency-Key`. Reuse the same value and body on retries, including after a timeout; a missing response does not prove the action failed.

For rate limits, follow the server’s retry guidance and back off. See [HTTP errors](https://developer.brigg.app/http#errors) and [safe retries and limits](https://developer.brigg.app/reliability).

| HTTP status | Code | What to do |
| --- | --- | --- |
| 400 | `invalid_json` | Send a JSON object with Content-Type: application/json. |
| 400 | `invalid_input` | Check the request fields and types. Supply a stable Idempotency-Key containing 1–200 characters. |
| 401 | `invalid_key` | The workspace API key is missing, invalid or revoked. |
| 403 | `forbidden` | Check the key’s operation and resource grants. Supply Brigg-Act-As with a member authorized by the key’s delegation grant. The selected member must be active and approved by the credential. This selects whose private data is used; the credential supplies permissions. Private ownership and project boundaries still apply. |
| 404 | `not_found` | The requested operation or resource is not available to this credential. |
| 429 | `rate_limited` | Wait for Retry-After before retrying. Reuse the original Idempotency-Key. |

## Next steps

[Download OpenAPI](https://developer.brigg.app/openapi.json) · [Versioning & retirement](https://developer.brigg.app/versioning)

## Examples

### Example request

Fictional values. Replace IDs and business details with values from your workspace.
#### cURL


```sh
curl 'https://api.brigg.app/v1/operations/images.GenerateImage' \
  -H "Authorization: Bearer $BRIGG_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Brigg-Act-As: $BRIGG_ACT_AS" \
  -H "Idempotency-Key: $BRIGG_REQUEST_ID" \
  --data-raw '{
  "prompt": "A quiet mountain lake at sunrise"
}'
```

#### TypeScript


```typescript
const actAs = process.env.BRIGG_ACT_AS;
if (!actAs) throw new Error("Set BRIGG_ACT_AS to an approved member account ID.");

const requestId = process.env.BRIGG_REQUEST_ID;
if (!requestId) throw new Error("Set BRIGG_REQUEST_ID once per action and reuse it on retries.");

const response = await fetch("https://api.brigg.app/v1/operations/images.GenerateImage", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BRIGG_API_KEY}`,
    "Content-Type": "application/json",
    "Brigg-Act-As": actAs,
    "Idempotency-Key": requestId, // Create once per action; reuse on retries.
  },
  body: JSON.stringify({
    "prompt": "A quiet mountain lake at sunrise"
  }),
});
const result = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${result.error} — ${result.message}`);
console.log(result);
```

#### Python


```python
import json
import os
from urllib.request import Request, urlopen
from urllib.error import HTTPError

request_id = os.environ["BRIGG_REQUEST_ID"]  # Reuse for retries of this action.
payload = {
  "prompt": "A quiet mountain lake at sunrise"
}
request = Request(
    "https://api.brigg.app/v1/operations/images.GenerateImage",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": f"Bearer {os.environ['BRIGG_API_KEY']}",
        "Content-Type": "application/json",
        "Brigg-Act-As": os.environ["BRIGG_ACT_AS"],
        "Idempotency-Key": request_id,  # Create once per action; reuse on retries.
    },
    method="POST",
)
try:
    with urlopen(request) as response:
        print(json.load(response))
except HTTPError as error:
    print(error.code, json.load(error))
    raise
```

#### Response example


```json
{
  "url": "https://example.com",
  "ext": "png"
}
```

## JSON schemas


```json-schema-request
{
  "type": "object",
  "properties": {
    "prompt": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000,
      "description": "What to draw. No words inside the image."
    },
    "aspect_ratio": {
      "type": "string",
      "enum": [
        "1:1",
        "2:3",
        "3:2",
        "3:4",
        "4:3",
        "4:5",
        "5:4",
        "9:16",
        "16:9",
        "21:9"
      ],
      "description": "Requested image proportions, using one of the supported values."
    },
    "size": {
      "type": "string",
      "enum": [
        "1K",
        "2K",
        "4K"
      ],
      "description": "Resolution; 1K when omitted. Bigger costs the org more."
    },
    "reference_files": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Display name."
          },
          "media_type": {
            "type": "string",
            "minLength": 1,
            "description": "image/png, image/jpeg, image/gif or image/webp."
          },
          "data": {
            "type": "string",
            "minLength": 1,
            "description": "The bytes, base64."
          }
        },
        "required": [
          "name",
          "media_type",
          "data"
        ],
        "additionalProperties": false
      },
      "maxItems": 3,
      "description": "Pictures that steer the generation — a product photo to keep faithful, a sketch, a style to follow. Pictures only, never a document."
    }
  },
  "required": [
    "prompt"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "prompt": "A quiet mountain lake at sunrise"
    }
  ]
}
```


```json-schema-response
{
  "type": "object",
  "properties": {
    "url": {
      "type": "string",
      "description": "A short-lived, caller-private download URL for the bytes."
    },
    "ext": {
      "type": "string",
      "description": "png / jpg / … from the bytes."
    },
    "bytes": {
      "type": "number",
      "description": "Size of the generated image in bytes."
    }
  },
  "required": [
    "url",
    "ext"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "url": "https://example.com",
      "ext": "png"
    }
  ]
}
```

