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

# Initialize a image reference upload

> Prepare a JPG, PNG or WebP reference upload up to 8 MiB. Use images_upload_sign_parts to get PUT URLs, upload the bytes, then call images_upload_complete and use its fileKey when generating.

Prepare a JPG, PNG or WebP reference upload up to 8 MiB. Use images\_upload\_sign\_parts to get PUT URLs, upload the bytes, then call images\_upload\_complete and use its fileKey when generating.

```http theme={null}
POST https://api.voicecheap.ai/v1/actions/images_upload_initialize
```

## Authentication and permissions

**x-api-key** `string` *required*

Send a VoiceCheap API key in this header. Authorization: Bearer with the same API key is also supported. OAuth access tokens are accepted only by
MCP, not by this REST endpoint.

Required permissions: `images:write`.

An active paid subscription is required. Permissions do not change team roles, resource ownership, media credits, or plan limits.

## Parameters

**requestId** `string`

Optional at the transport boundary: the server injects an identifier before validation when omitted. Supply your own stable UUID v4 to recover safely from a lost response.

Format: "uuid". Pattern: `^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$`.

**filename** `string` *required*

The image filename, with an extension matching contentType.

Minimum length: 1. Maximum length: 250. Pattern: `\.(?:jpe?g|png|webp)$`.

**contentType** `string` *required*

Text value.

Allowed values: "image/jpeg", "image/png", "image/webp".

**fileSize** `integer` *required*

Exact file size in bytes, up to 8 MiB.

Minimum: 1. Maximum: 8388608.

> [accordion] Complete input schema
>
> The JSON Schema below preserves the exact field names, nested types, defaults, bounds, and accepted values exposed by discovery. Additional cross-field rules are listed in the operation notes.
>
> ```json theme={null}
> {
>   "type": "object",
>   "properties": {
>     "requestId": {
>       "description": "UUID v4 for this action. Reuse the same ID with identical arguments on retries.",
>       "type": "string",
>       "format": "uuid",
>       "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
>     },
>     "filename": {
>       "type": "string",
>       "minLength": 1,
>       "maxLength": 250,
>       "pattern": "\\.(?:jpe?g|png|webp)$",
>       "description": "The image filename, with an extension matching contentType."
>     },
>     "contentType": {
>       "type": "string",
>       "enum": ["image/jpeg", "image/png", "image/webp"]
>     },
>     "fileSize": {
>       "type": "integer",
>       "minimum": 1,
>       "maximum": 8388608,
>       "description": "Exact file size in bytes, up to 8 MiB."
>     }
>   },
>   "required": ["filename", "contentType", "fileSize"],
>   "additionalProperties": false
> }
> ```

## Idempotency

Use a UUID v4 in requestId or the Idempotency-Key HTTP header for each mutation. Reuse the same identifier and identical arguments after a network failure. If both are supplied, they must match. Replaying a saved request does not repeat the operation or charge another monthly call. Failed or interrupted requests are not restarted automatically.

Every mutation can return HTTP 202 when a retry finds the same request still running, even when its first execution is normally synchronous. If execution completed but resultStored is false, a retry returns HTTP 200 with saved request state instead of the original result. Retrieve the output through its domain history, result, or download action.

## Request examples

Replace example resource identifiers and media keys with values returned for your account. Keep the request identifier stable when retrying the same mutation.

```bash cURL theme={null}
curl --request POST 'https://api.voicecheap.ai/v1/actions/images_upload_initialize' \
  --header "x-api-key: $VOICECHEAP_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"requestId":"85d80887-5e1c-4a86-bbad-bb105487f7e4","filename":"reference.png","contentType":"image/png","fileSize":7340032}'
```

```javascript JavaScript theme={null}
const input = {
  requestId: '85d80887-5e1c-4a86-bbad-bb105487f7e4',
  filename: 'reference.png',
  contentType: 'image/png',
  fileSize: 7340032,
};
const response = await fetch('https://api.voicecheap.ai/v1/actions/images_upload_initialize', {
  method: 'POST',
  headers: {
    'x-api-key': process.env.VOICECHEAP_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(input),
});
const body = await response.json();
if (!response.ok) throw new Error(body.code + ': ' + body.message);
console.log(body);
```

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://api.voicecheap.ai/v1/actions/images_upload_initialize",
    headers={"x-api-key": os.environ["VOICECHEAP_API_KEY"]},
    json={"requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4", "filename": "reference.png", "contentType": "image/png", "fileSize": 7340032},
    timeout=120,
)
body = response.json()
if not response.ok:
    raise RuntimeError(f"{body.get('code')}: {body.get('message')}")
print(body)
```

## Response

A successful first execution returns HTTP 200 with the operation result under data. A replay may return saved request state instead. The example shows one supported response, not every optional field.

A new multipart image-reference upload session, the future object key, the part size in bytes, and the maximum parallel-upload count. This does not upload any image bytes or make key ready for generation.

```json HTTP 200 theme={null}
{
  "data": {
    "uploadId": "c547fb7f-f334-46a8-a8bb-80b5b343889a",
    "key": "uploads/example-user/2502829e-3fde-4aad-b3c7-ce0f779fa2e6-reference.png",
    "partSize": 5242880,
    "maxConcurrency": 4
  },
  "requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4"
}
```

```json HTTP 202 replay_running theme={null}
{
  "data": {
    "requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4",
    "operation": "images_upload_initialize",
    "createdAt": 1792144800000,
    "updatedAt": 1792144820000,
    "status": "running",
    "pollAfterSeconds": 5
  },
  "requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4"
}
```

```json HTTP 200 replay_completed_without_result theme={null}
{
  "data": {
    "requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4",
    "operation": "images_upload_initialize",
    "createdAt": 1792144800000,
    "updatedAt": 1792144820000,
    "status": "completed",
    "resultStored": false,
    "message": "The action completed. Retrieve its output from the corresponding history or resource action."
  },
  "requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4"
}
```

## Result fields

| Field | Description |
| - | - |
| `data.uploadId` | UUID identifying the active upload session. Pass it to the remaining upload actions. |
| `data.key` | Future owned object key. Use fileKey from a successful completion as the generation reference. |
| `data.partSize` | Required part size in bytes, except that the final part contains the remaining bytes. |
| `data.maxConcurrency` | Maximum suggested number of parallel part uploads: 4. |

## Recover and poll this request

Use the same identifier even after a lost connection. If resultStored is false, retrieve the output through the corresponding history, result, or download action. Never start a second generation merely to check progress.

```bash theme={null}
curl --request POST 'https://api.voicecheap.ai/v1/actions/action_request_get' \
  --header "x-api-key: $VOICECHEAP_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"requestId":"85d80887-5e1c-4a86-bbad-bb105487f7e4","operation":"images_upload_initialize"}'
```

```json HTTP 200 theme={null}
{
  "data": {
    "requestId": "85d80887-5e1c-4a86-bbad-bb105487f7e4",
    "operation": "images_upload_initialize",
    "status": "completed",
    "createdAt": 1792144800000,
    "updatedAt": 1792144820000,
    "resultStored": true,
    "result": {
      "uploadId": "c547fb7f-f334-46a8-a8bb-80b5b343889a",
      "key": "uploads/example-user/2502829e-3fde-4aad-b3c7-ce0f779fa2e6-reference.png",
      "partSize": 5242880,
      "maxConcurrency": 4
    }
  }
}
```

## Operation notes

* Requires images:write; no additional upload scope is needed.
* filename is trimmed, must contain 1–250 characters, and must end in .jpg, .jpeg, .png, or .webp. Its extension must match contentType: image/jpeg, image/png, or image/webp. fileSize is the exact integer byte count, from 1 to 8,388,608.
* The shared upload implementation returns partSize 5 MiB (5,242,880 bytes) for these references. A file of at most 5 MiB uses one part; a larger file up to 8 MiB uses two. Request PUT URLs with images\_upload\_sign\_parts, upload the bytes, then call images\_upload\_complete.
* Use the fileKey returned by completion as referenceImageKey in images\_generate. The initialize result uses key, not fileKey. Do not pass key to generation before completion.
* The production upload session expires after 24 hours. Signed part URLs expire after one hour. Completion and abort remove the active session; sign-parts and complete then return Upload not found. Neither response includes an expiresAt field.
* This action uses the connected user’s own creations and uploads, including when the credential is connected in a team context.
* Use a UUID v4 requestId, or the HTTP Idempotency-Key header, and reuse it with identical inputs when retrying. The integration layer records each mutation and returns its recorded state or result without rerunning it. A failed or interrupted request is not automatically retried.
* The filename in the object key is sanitized and may be shortened. Keep the exact returned key and uploadId; do not construct them yourself. Image bytes are validated during generation as well as the declared size and type during upload.

## Usage

Each successful invocation consumes one monthly API/MCP call. Media credits and the operation's own generation allowances also apply.

## Errors

| HTTP status | Code | Meaning or recovery |
| - | - | - |
| 400 | `CREDENTIAL_IN_QUERY` | Credentials were supplied in an access\_token or api\_key query parameter. Send credentials in headers. |
| 400 | `IDEMPOTENCY_CONFLICT` | The Idempotency-Key header and requestId body field must match. |
| 400 | `INVALID_REQUEST_ID` | requestId or Idempotency-Key is not a UUID v4. |
| 400 | `REFERENCE_IMAGE_INVALID` | The filename extension does not match the declared image contentType. |
| 400 | `VALIDATION_ERROR` | An argument is missing, has an unsupported value, exceeds its limit, or is not part of the strict input schema. |
| 401 | `API_KEY_EXPIRED` | The API key has expired. |
| 401 | `INVALID_API_KEY` | Provide a valid, unexpired API key. |
| 401 | `INVALID_CREDENTIAL` | The Authorization header is malformed or conflicts with x-api-key. |
| 401 | `MISSING_CREDENTIAL` | No usable header credential was supplied, or it exceeded 4096 characters. |
| 401 | `USER_NOT_FOUND` | The credential's account no longer exists. |
| 403 | `ACCOUNT_UNAVAILABLE` | The acting or billing account is unavailable or being deleted. |
| 403 | `AMBIGUOUS_TEAM_API_KEY` | The credential's user belongs to more than one team, so the billing context is ambiguous. |
| 403 | `INSUFFICIENT_SCOPE` | Grant every required permission or choose another credential. |
| 403 | `INTEGRATION_PLAN_UNSUPPORTED` | The account's integration limits could not be verified. |
| 403 | `SUBSCRIPTION_REQUIRED` | Use an active paid subscription. |
| 403 | `TEAM_OWNER_NOT_FOUND` | The effective team owner account could not be found. |
| 409 | `CONCURRENT_ACTION_LIMIT_REACHED` | This account already has 10 integration actions running. Poll an existing request before starting another. |
| 409 | `IDEMPOTENCY_CONFLICT` | The request identifier was already used with different arguments; a header/body identifier mismatch returns HTTP 400 with the same code. |
| 429 | `INTEGRATION_MONTHLY_LIMIT_REACHED` | Wait for the monthly reset or change plan. |
| 429 | `INTEGRATION_RATE_LIMIT_REACHED` | Wait for Retry-After when present and use backoff. |
| 500 | `INTERNAL_ERROR` | Check saved request state and resource history before deciding to retry a mutation. |
| 503 | `ACTION_RESULT_UNAVAILABLE` | The action ran but its result could not be saved. Inspect saved request state and resource history before starting a new generation. |
| 503 | `INTERNAL_ERROR` | The upload session could not be created or saved. Retry the same mutation identifier and inspect its recorded state. |
| 503 | `SERVER_RESTARTING` | The server is restarting. Retry shortly and keep the same request identifier for a mutation. |

```json theme={null}
{
  "code": "INSUFFICIENT_SCOPE",
  "message": "This credential does not permit the requested action.",
  "status": 403,
  "details": {
    "requiredScopes": ["images:write"]
  }
}
```


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