# Errors

> Eevo docs. Every page as Markdown is listed at https://eevo.io/llms.txt; the API is described at https://eevo.io/api/openapi.json.

Error responses provided by the Eevo API have the following format:

```json
{
  "error": {
    "type": "insufficient_credit",
    "message": "Your balance is $0.00. Buy credits in the Eevo console."
  }
}
```

| Status | Type | Meaning |
|---|---|---|
| 400 | `invalid_request` | The request body does not match the schema or exceeds a limit, and the message names the field. A request for a decision that does not exist in your organization, or is not shared with you, gets this type with status 410. |
| 400 | `too_many_overlap_pairs` | The consequence-based decision has more consequence pairs to check for overlap than the limit allows. Send fewer consequences, or give each one only the stakeholders it affects. |
| 401 | `authentication` | The API key is missing, invalid or revoked. A 403 with the same type means the key is not allowed to change who sees the decision or to publish it. |
| 402 | `insufficient_credit` | The balance cannot pay for the request, or the request asks for the EU and your organization has neither bought credit nor has credit. |
| 409 | `model_unavailable` | Eevo-1 is not available in this mode right now (no serving endpoint). |
| 409 | `revision_conflict` | The decision you are revising already has a newer revision, which the message names. Revise that one instead. |
| 429 | `rate_limited` | The request hit a rate limit, or your organization already has the maximum number of consequence-based decisions running. Retry after the number of seconds in Retry-After. |
| 503 | `model_warming` | The model is starting after being idle, which takes a few minutes. Retry after the number of seconds in Retry-After. Nothing is charged. |
| 503 | `region_unavailable` | A request for the EU found no EU server available. Retry after the number of seconds in Retry-After. Nothing is charged. |
| 5xx | `server_error` | The model did not answer (502), the request timed out (504), or Eevo hit an unexpected error. Retry with backoff. Nothing is charged. |

Errors are not charged.

## Retrying

Retry a `429` or a `5xx` after the number of seconds in the response's `Retry-After` header, or after a minute if there is none, and give up after a few attempts. A `409` `model_unavailable` also clears on its own, so it can be retried after a minute. Other errors do not clear on their own, so retrying them does not help. Below is an example of a loop that retries `429` and `5xx` responses:

**Python**

```python
import os
import time

import requests

HEADERS = {"Authorization": f"Bearer {os.environ['EEVO_API_KEY']}"}

def ask(body):
    for _ in range(5):
        response = requests.post("https://eevo.io/api/v1/systemone", headers=HEADERS, json=body)
        if response.ok:
            return response.json()
        retryable = response.status_code == 429 or response.status_code >= 500
        if not retryable:
            error = response.json()["error"]
            raise RuntimeError(f"{error['type']}: {error['message']}")
        time.sleep(float(response.headers.get("Retry-After", 60)))
    raise RuntimeError("Eevo did not answer after 5 attempts")
```

**TypeScript**

```typescript
const headers = { Authorization: `Bearer ${process.env.EEVO_API_KEY}`, 'Content-Type': 'application/json' };
const sleep = seconds => new Promise(resolve => setTimeout(resolve, seconds * 1000));

async function ask(body) {
  for (let attempt = 0; attempt < 5; attempt++) {
    const response = await fetch('https://eevo.io/api/v1/systemone', { method: 'POST', headers, body: JSON.stringify(body) });
    if (response.ok) return await response.json();
    const retryable = response.status === 429 || response.status >= 500;
    if (!retryable) {
      const { error } = await response.json();
      throw new Error(`${error.type}: ${error.message}`);
    }
    await sleep(Number(response.headers.get('Retry-After') ?? 60));
  }
  throw new Error('Eevo did not answer after 5 attempts');
}
```

**JavaScript**

```javascript
const headers = { Authorization: `Bearer ${process.env.EEVO_API_KEY}`, 'Content-Type': 'application/json' };
const sleep = seconds => new Promise(resolve => setTimeout(resolve, seconds * 1000));

async function ask(body) {
  for (let attempt = 0; attempt < 5; attempt++) {
    const response = await fetch('https://eevo.io/api/v1/systemone', { method: 'POST', headers, body: JSON.stringify(body) });
    if (response.ok) return await response.json();
    const retryable = response.status === 429 || response.status >= 500;
    if (!retryable) {
      const { error } = await response.json();
      throw new Error(`${error.type}: ${error.message}`);
    }
    await sleep(Number(response.headers.get('Retry-After') ?? 60));
  }
  throw new Error('Eevo did not answer after 5 attempts');
}
```
