Reference · Errors
Errors
Cosavu uses conventional HTTP response codes and returns a consistent JSON error shape for every failure. Both SDKs raise typed exception classes you can catch directly.
Error response shape
Every error response is JSON with a top-level error object:
{
"color:#3b82f6">"error": {
"color:#3b82f6">"type": "invalid_request_error",
"color:#3b82f6">"code": "missing_parameter",
"color:#3b82f6">"message": "Required parameter 'prompt' was not provided.",
"color:#3b82f6">"param": "prompt",
"color:#3b82f6">"requestId": "req_a1b2c3d4e5"
}
}Fields
| Field | Description |
|---|---|
type | Broad category — invalid_request_error, authentication_error, rate_limit_error, api_error. |
code | Machine-readable code for the specific failure. Stable across versions. |
message | Human-readable description. Don't depend on the exact wording. |
param | Optional. The parameter that caused the error, if applicable. |
requestId | Always present. Include this when contacting support. |
Status codes
| Status | Type | Meaning |
|---|---|---|
| 200 | — | Request succeeded. |
| 400 | invalid_request_error | Missing or invalid parameters. |
| 401 | authentication_error | Missing or invalid API key. |
| 403 | permission_error | Key lacks the scope needed for this endpoint. |
| 404 | not_found_error | Resource doesn't exist or isn't visible to this tenant. |
| 409 | conflict_error | Request conflicts with current resource state. |
| 422 | validation_error | Parameters passed type checks but failed business rules. |
| 429 | rate_limit_error | Quota exceeded. See Retry-After header. |
| 500 | api_error | Server error. Retry with backoff. |
| 503 | service_unavailable | Temporary outage. Retry with backoff. |
Handling errors in code
Both SDKs raise typed exception classes. Catch them by base class for broad handling, or by specific class for targeted recovery:
import { Cosavu, CosavuError, RateLimitError, AuthenticationError, } from "@cosavu/sdk" const cosavu = new Cosavu() try { const result = await cosavu.context.optimize({ prompt: "..." }) } catch (e) { if (e instanceof RateLimitError) { console.log("Slow down. Retry after:", e.retryAfter) } else if (e instanceof AuthenticationError) { console.log("Key is bad or missing.") } else if (e instanceof CosavuError) { console.log(e.code, e.message, e.requestId) } else { throw e } }
Retry strategy
The SDK automatically retries idempotent requests on 5xx and 429 responses using exponential backoff with jitter. Default: 2 retries, 250ms initial delay, capped at 8 seconds.
Configure retry behaviour at the client level:
const cosavu = new Cosavu({ maxRetries: 5, // default 2 retryInitialDelay: 500, // ms, default 250 retryMaxDelay: 16_000, // ms, default 8000 })
Idempotency
Pass an Idempotency-Key header to safely retry any request. The SDK adds one automatically for write endpoints. Keys are valid for 24 hours.
Common error codes
| Code | What to do |
|---|---|
missing_parameter | Add the missing field listed in error.param. |
invalid_api_key | Check that COSAVU_API_KEY is set and starts with cv_. |
scope_insufficient | Generate a new key with the required scope. |
tenant_not_found | Confirm the tenant exists in this project. |
rate_limit_exceeded | Honour the Retry-After header. Consider a higher tier. |
context_too_large | Reduce input size or split into multiple requests. |
budget_exceeded | Increase budget parameter or upgrade plan. |
internal_error | Retry with backoff. Contact support with requestId if persistent. |