> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.videogen.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.videogen.io/_mcp/server.

# Errors

> Error response format, HTTP status codes, and common error codes returned by the VideoGen API.

When a request fails, the API returns a non-2xx HTTP status code with a JSON body matching the `ApiError` schema:

```json
{
  "message": "API key is invalid or has been revoked.",
  "code": "invalid_api_key"
}
```

| Field     | Type                  | Description                                                                                                                      |
| --------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `message` | `string`              | A human-readable explanation. Safe to display to end users.                                                                      |
| `code`    | `string \| undefined` | A machine-readable error code in `snake_case`. Not present on all errors yet — check the HTTP status code as the primary signal. |

## HTTP status codes

| Status | Meaning                                                                      |
| ------ | ---------------------------------------------------------------------------- |
| `400`  | Bad request — invalid parameters, missing required fields, or malformed body |
| `401`  | Unauthorized — missing or invalid API key                                    |
| `403`  | Forbidden — your API key doesn't have access to this resource                |
| `404`  | Not found — the resource doesn't exist or doesn't belong to your team        |
| `429`  | Rate limit exceeded — back off and retry (see [Rate Limits](/rate-limits))   |
| `500`  | Internal server error — something went wrong on our end                      |

## Error codes

| Code                 | Typical status | Description                                                                    |
| -------------------- | -------------- | ------------------------------------------------------------------------------ |
| `missing_api_key`    | 401            | No `Authorization: Bearer ...` header was provided, or the token is empty      |
| `invalid_api_key`    | 401            | The provided API key is invalid or has been revoked                            |
| `invalid_id`         | 400            | A resource id (file, execution, endpoint) is malformed or has the wrong prefix |
| `invalid_parameters` | 400            | One or more request parameters failed validation                               |

More codes will be added over time. Always use the HTTP status code as the primary indicator, and treat `code` as supplemental information for programmatic branching.

## Handling errors in SDKs

Both SDKs throw a typed error that includes the HTTP status and the `ApiError` body:

#### TypeScript

```typescript
import { VideoGen, VideoGenError } from "@videogen/sdk";

const client = new VideoGen({ apiKey: "sk_videogen_live_..." });

try {
  await client.tools.generateImage({ prompt: "" });
} catch (err) {
  if (err instanceof VideoGenError) {
    console.error(err.status); // 400
    console.error(err.body); // { message, code, ... }
  }
}
```

#### Python

```python
from videogen import VideoGen, VideoGenError

client = VideoGen(api_key="sk_videogen_live_...")

try:
    client.tools.generate_image(prompt="")
except VideoGenError as err:
    print(err.status)  # 400
    print(err.body)  # {"message": "...", "code": "...", ...}
```