CosavuCosavu

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

FieldDescription
typeBroad category — invalid_request_error, authentication_error, rate_limit_error, api_error.
codeMachine-readable code for the specific failure. Stable across versions.
messageHuman-readable description. Don't depend on the exact wording.
paramOptional. The parameter that caused the error, if applicable.
requestIdAlways present. Include this when contacting support.

Status codes

StatusTypeMeaning
200Request succeeded.
400invalid_request_errorMissing or invalid parameters.
401authentication_errorMissing or invalid API key.
403permission_errorKey lacks the scope needed for this endpoint.
404not_found_errorResource doesn't exist or isn't visible to this tenant.
409conflict_errorRequest conflicts with current resource state.
422validation_errorParameters passed type checks but failed business rules.
429rate_limit_errorQuota exceeded. See Retry-After header.
500api_errorServer error. Retry with backoff.
503service_unavailableTemporary 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

CodeWhat to do
missing_parameterAdd the missing field listed in error.param.
invalid_api_keyCheck that COSAVU_API_KEY is set and starts with cv_.
scope_insufficientGenerate a new key with the required scope.
tenant_not_foundConfirm the tenant exists in this project.
rate_limit_exceededHonour the Retry-After header. Consider a higher tier.
context_too_largeReduce input size or split into multiple requests.
budget_exceededIncrease budget parameter or upgrade plan.
internal_errorRetry with backoff. Contact support with requestId if persistent.