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

# Response & Error Codes

> Understand the standard API response structure and error codes

All API responses follow a consistent response structure and include a status code that indicates whether the request was successful or failed.

## Response Structure

All API endpoints return responses in the following JSON format:

```json theme={null}
{
  "code": 200,
  "msg": "success",
  "data": {}
}
```

| Field  | Type    | Description                                                                                          |
| :----- | :------ | :--------------------------------------------------------------------------------------------------- |
| `code` | integer | Status code indicating the result of the request. `200` means success; other values indicate errors. |
| `msg`  | string  | Human-readable message describing the result of the request.                                         |
| `data` | object  | The response payload returned by the API. When an error occurs, this field is usually `null`.        |

## HTTP Status Codes

In this API, the HTTP status code is consistent with the `code` field in the response body.

For example:

* When a request succeeds, the server returns HTTP `200`, and the response body contains `"code": 200`.
* When a request fails, the server returns the corresponding HTTP status code, and the same value appears in the `code` field.

Example:

```http theme={null}
HTTP/1.1 400 Bad Request
```

```json theme={null}
{
  "code": 400,
  "msg": "Invalid request parameters",
  "data": null
}
```

This means:

* HTTP status code indicates the request result at the protocol level.
* `code` field provides the same status information in the response body for easier client-side handling.
* Clients can determine whether a request succeeded by checking either the HTTP status code or the `code` field.

## Common Error Codes

| Code  | Description                                    |
| :---- | :--------------------------------------------- |
| `200` | Success                                        |
| `400` | Invalid request parameters                     |
| `401` | Unauthorized (invalid or expired API key)      |
| `402` | Insufficient balance or credits                |
| `403` | Forbidden (account disabled or IP not allowed) |
| `405` | Method not allowed                             |
| `409` | Request conflict or duplicate request          |
| `415` | Unsupported media type                         |
| `429` | Rate limit exceeded                            |
| `500` | Internal server error                          |

## Error Response Examples

Below are common error scenarios you may encounter, along with their response bodies:

**Invalid or missing API key:**

```json theme={null}
{
  "code": 401,
  "msg": "Unauthorized",
  "data": null
}
```

**Asset not found:**

```json theme={null}
{
  "code": 400,
  "msg": "Asset not found",
  "data": null
}
```

**Insufficient account balance:**

```json theme={null}
{
  "code": 402,
  "msg": "Insufficient balance or credits",
  "data": null
}
```

**Unsupported file format:**

```json theme={null}
{
  "code": 415,
  "msg": "Unsupported media type",
  "data": null
}
```

**Rate limit exceeded:**

```json theme={null}
{
  "code": 429,
  "msg": "Rate limit exceeded",
  "data": null
}
```

**Internal server error:**

```json theme={null}
{
  "code": 500,
  "msg": "Internal server error",
  "data": null
}
```

## Troubleshooting FAQ

| Problem                      | Possible Cause                                    | Solution                                                                                                                                       |
| ---------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`           | API key is missing, invalid, or expired           | Verify your API key in the `Authorization` header. Regenerate a new key from the [Console](https://api-platform.memories.ai/stripe) if needed. |
| `402 Insufficient balance`   | Your account balance is depleted                  | Top up your account balance in the Console.                                                                                                    |
| `400 Asset not found`        | The `asset_id` does not exist or has been deleted | Verify the `asset_id` is correct. Re-upload the file if it was deleted.                                                                        |
| `415 Unsupported media type` | The uploaded file format is not supported         | Check the supported file formats in the [Upload](/visual-intelligence/base/upload) documentation.                                              |
| `429 Rate limit exceeded`    | Too many requests in a short time                 | Implement retry logic with exponential backoff. See [Rate Limit](/visual-intelligence/getting-started/rate-limit) for details.                 |
| `500 Internal server error`  | Server-side issue                                 | Retry after a few seconds. If persistent, contact [support@memories.ai](mailto:support@memories.ai).                                           |

## Notes

<Note>
  * The `msg` field provides a human-readable description of the request result.
  * The `data` field contains the response payload when the request succeeds.
  * When an error occurs, `data` will usually be `null`.
  * Clients should handle errors based on the returned status code.
</Note>
