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

# Errors

> Learn about error handling in the Meibel API

The Meibel API uses conventional HTTP response codes to indicate the success or failure of an API request. In general, codes in the `2xx` range indicate success, codes in the `4xx` range indicate an error due to the information provided (e.g., a required parameter was missing), and codes in the `5xx` range indicate an error with our servers.

## HTTP Status Codes

| Code                               | Description                                                                                      |
| ---------------------------------- | ------------------------------------------------------------------------------------------------ |
| 200 - OK                           | The request was successful.                                                                      |
| 201 - Created                      | The resource was successfully created.                                                           |
| 400 - Bad Request                  | The request was unacceptable, often due to missing a required parameter.                         |
| 401 - Unauthorized                 | No valid API key provided.                                                                       |
| 403 - Forbidden                    | The API key doesn't have permissions to perform the request.                                     |
| 404 - Not Found                    | The requested resource doesn't exist.                                                            |
| 422 - Validation Error             | The request was well-formed but was unable to be processed due to semantic errors.               |
| 429 - Too Many Requests            | Too many requests hit the API too quickly. We recommend an exponential backoff of your requests. |
| 500, 502, 503, 504 - Server Errors | Something went wrong on our end. (These are rare.)                                               |

## Error Response Format

All API errors include a JSON response body:

```json theme={null}
{
  "message": "A human-readable error message",
  "detail": [
    {
      "loc": ["body", "field_name"],
      "msg": "Field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Error Handling in SDKs

<CodeGroup>
  ```python Python theme={null}
  from meibel import MeibelClient
  from meibel.exceptions import ApiError, AuthenticationError, NotFoundError
  import os

  client = MeibelClient(api_key=os.getenv("MEIBEL_API_KEY"))

  try:
      result = client.documents.get_result("nonexistent-id")
  except AuthenticationError as e:
      print(f"Invalid API key: {e}")
  except NotFoundError as e:
      print(f"Not found: {e}")
  except ApiError as e:
      print(f"API error ({e.status_code}): {e}")
  ```

  ```typescript TypeScript theme={null}
  import { MeibelClient, ApiError, AuthenticationError, NotFoundError } from 'meibel';

  const client = new MeibelClient({ apiKey: process.env.MEIBEL_API_KEY });

  try {
    const result = await client.documents.getResult('nonexistent-id');
  } catch (e) {
    if (e instanceof AuthenticationError) {
      console.error('Invalid API key:', e.message);
    } else if (e instanceof NotFoundError) {
      console.error('Not found:', e.message);
    } else if (e instanceof ApiError) {
      console.error(`API error (${e.statusCode}):`, e.message);
    }
  }
  ```
</CodeGroup>

## Tips for Error Handling

<Note>
  Always implement proper error handling in your application to provide a good user experience and facilitate debugging.
</Note>

<Steps>
  <Step title="Handle expected errors">
    Handle common error cases (401, 404, 422, 429) gracefully in your application
  </Step>

  <Step title="Implement retry logic">
    Use exponential backoff for retrying failed requests, especially for rate limit errors (429)
  </Step>

  <Step title="Log errors">
    Log error details to help with troubleshooting
  </Step>

  <Step title="Provide user feedback">
    Translate API errors into helpful messages for your users
  </Step>
</Steps>

## Getting Help

If you're experiencing persistent errors:

1. Ensure you have the complete error message
2. Contact our support team at [support@meibel.ai](mailto:support@meibel.ai) with details
3. For SDK-specific issues, open an issue on GitHub
