---
title: "Error Enhancement"
canonical: https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance/tools/error-enhancement
markdown: https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance/tools/error-enhancement.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/01%20Cloud%20Platform/99%20API%20Reference/10%20AI%20Assistance/02%20Tools/03%20Error%20Enhancement
modified: 2026-11-02
index: https://www.quantconnect.com/llms.txt
---

# Error Enhancement

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Cloud Platform](https://www.quantconnect.com/docs/v2/cloud-platform.md) > [API Reference](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference.md) > [AI Assistance](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance.md) > [Tools](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/ai-assistance/tools.md) > Error Enhancement

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

Show additional context and suggestions for error messages.

## Request

Show additional context and suggestions for error messages. The `/ai/tools/error-enhance` API accepts requests in the following format:

| `ErrorEnhanceRequest` Model - Request to show additional context and suggestions for error messages. |  |
| --- | --- |
| language | `string Enum required example: Py` Programming language for the code completion. Options : ['C#', 'Py'] |
| error | `Error object required` Error information. |
| Example | `{ "language": "Py", "error": { "message": "string", "stacktrace": "string" } }` |

| `Error` Model - Error information. |  |
| --- | --- |
| message | `string required` Error message. |
| stacktrace | `string` Stack trace of the error. |
| Example | `{ "message": "string", "stacktrace": "string" }` |

## Responses

The `/ai/tools/error-enhance` API provides a response in the following format:

### 200 Success

| `ErrorEnhanceResponse` Model - Response to error enhancement request. |  |
| --- | --- |
| state | `string example: End` State of the code completion. |
| version | `number example: 2.0` Version of the response. |
| payload | `string` Error message suggestions. |
| payloadType | `string example: String` Type of the payload. |
| Example | `{ "state": "End", "version": 2.0, "payload": "string", "payloadType": "String" }` |

### 401 Authentication Error

| `UnauthorizedError` Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash. |  |
| --- | --- |
| www_authenticate | `string` Header |

## Examples

The following example demonstates how to get additional context and suggestions for error messages through the cloud API.

```
from base64 import b64encode
from hashlib import sha256
from time import time
from requests import get, post
BASE_URL = 'https://www.quantconnect.com/api/v2/'

# You need to replace these with your actual credentials.
# You can request your credentials at https://www.quantconnect.com/settings/
# You can find our organization ID at https://www.quantconnect.com/organization/
USER_ID = 0
API_TOKEN = '____'
ORGANIZATION_ID = '____'

def get_headers():
    # Get timestamp
    timestamp = f'{int(time())}'
    time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8')

    # Get hased API token
    hashed_token = sha256(time_stamped_token).hexdigest()
    authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8')
    authentication = b64encode(authentication).decode('ascii')

    # Create headers dictionary.
    return {
        'Authorization': f'Basic {authentication}',
        'Timestamp': timestamp
    }

# Authenticate to verify credentials
response = post(f'{BASE_URL}/authenticate', headers = get_headers())
print(response.json())

# --------------------

### Error Enhancement
# Send a POST request to the /ai/tools/error-enhance endpoint to enhance error message
response = post(f'{BASE_URL}/ai/tools/error-enhance/', headers=get_headers(), json={
    "language": "Python",  # Programming language of the code
    "error": {  # Error details
        "message": '''  at initialize
        self._option = self.add_index_option("SPX", Resolution.MINUTE, "SPXW").symbol
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    in c1afe80a-e056-4841-b0c1-d9c562cf2bd8.py: line 15
    The specified market wasn't found in the markets lookup. Requested: spxw. You can add markets by calling QuantConnect.Market.Add(string,int) (Parameter 'market')''',  # Error message
        "stacktrace": ""  # Stacktrace (empty in this case)
    }
})
# Parse the JSON response
result = response.json()
# Check if the request was successful and print the enhanced error details
if result['success']:
    print("Enhanced Error Details:")
    print(result)
```
