Skip to content

Agent Error Codes ​

Every error the agent, session, file and webhook routes raise is a CognipeerAPIError. Branch on its errorCode — the machine-readable code of the response body — not on the message text.

New in 3.1.0

AgentActionErrorCodes, isAgentActionErrorCode(), and a fix to how errorCode is read: when error is just the message string ({ error: 'Webhook not found', code: 'not_found' }, the shape of the webhook routes), the top-level code is used, so not_found, forbidden, limit_reached, endpoint_disabled and delivery_pending are no longer lost. error.code still wins when both are present.

The error object ​

typescript
class CognipeerError extends Error {
  statusCode?: number;      // HTTP status
  response?: unknown;       // the parsed response body
}

class CognipeerAPIError extends CognipeerError {
  errorType?: string;       // the body's error.type
  errorCode?: string;       // the body's error.code (or a top-level `code`) — branch on this
  retryAfterMs?: number;    // parsed Retry-After, in milliseconds, when present
}

The agent routes answer { "error": { "message", "type", "code", ...extra } } with snake_case extras; the webhook routes answer { "error": "<message>", "code": "<code>" }. Extra fields live in error.response:

typescript
import { CognipeerAPIError, AgentActionErrorCodes, isAgentActionErrorCode } from '@cognipeer/console-sdk';

try {
  await client.agents.sessions.actions.resolve(conversationId, actionId, { decision: 'allow' });
} catch (error) {
  if (error instanceof CognipeerAPIError) {
    console.log(error.statusCode, error.errorCode, error.message);
    const body = error.response as { error?: { action_status?: string } };
    console.log(body.error?.action_status); // 'resolved' | 'cancelled' | 'expired'
  }
  if (isAgentActionErrorCode(error, AgentActionErrorCodes.NotPending)) { /* … */ }
}

Helpers ​

HelperUse
isAgentRunErrorCode(error, AgentRunErrorCodes.X)Run codes (conflict, concurrency, idempotency, timeout)
isAgentActionErrorCode(error, AgentActionErrorCodes.X)Session, approval, file and budget codes
error.errorCode === 'agent_not_found'Codes without a constant (listed below)

AgentRunErrorCodes: Conflict, AlreadyTerminal, ConcurrencyLimit, SyncTimeout, IdempotencyKeyConflict, IdempotencyKeySyncNotSupported.

AgentActionErrorCodes: SessionNotFound, SessionConflict, StorageUnavailable, StorageNotConfigured, AttachmentsDisabled, BucketInUse, NotFound, NotPending, ActionCancelled, Expired, Forbidden, AuthorizationUnavailable, MarkdownUnavailable, InvalidResolution, PendingAction, BudgetOverrideForbidden, InvalidBudget, BackgroundDisabled, BudgetReached.

Runs and Responses ​

StatuserrorCodeMeaning
409agent_run_conflictA run is already queued/running on this conversation (sync or background), including when you delete a session or update its budget during a run
504timeoutA synchronous turn exceeded the server ceiling. Tool side effects may have happened, so the SDK does not retry it (retryable: false). Use background: true
429agent_run_concurrency_limitThe tenant's concurrent background-run limit is reached
409idempotency_key_conflictIdempotency-Key reused with a different request
400idempotency_key_sync_not_supportedIdempotency-Key sent without background: true
409agent_run_already_terminalruns.cancel() on a finished run
400agent_background_disabledbackground: true, a budget resume or actions.resolve({ background }) on an agent with background execution disabled
404agent_not_foundNo agent with that key in the token's project
400agent_not_activesessions.create() for an agent that is not active
400invalid_requestA malformed request: for example session_id and conversation naming two different sessions, or agent missing from sessions.create()

Sessions ​

StatuserrorCodeMeaning
404session_not_foundNo such conversation in this project — also a session_id / conversation of another agent or project
400session_conflictsession_id / conversation and previous_response_id of one request name different sessions (session_id vs conversation alone is 400 invalid_request)
400invalid_metadatametadata is not up to 16 string pairs (keys 1–64 characters, values up to 512)
400invalid_limitsessions.list({ limit }) is not a whole number from 1 to 100
400invalid_statussessions.list({ status }) is not idle, running, requires_action or budget_paused
400invalid_cursorsessions.list({ after }) is not a cursor the API returned
409agent_run_conflictsessions.delete() or sessions.update() while a run is active

Budgets ​

StatuserrorCodeMeaning
400invalid_budgetThe budget is malformed, missing from sessions.update(), or not above what the session already spent
403budget_override_forbiddenThe agent's own session budget binds API callers: they may lower it, not raise or remove it
402budget_reachedThe session used up its budget; a new message is refused. error.response.error.spent_usd / max_cost_usd say how much. Raise it with sessions.update()

Approvals and questions ​

StatuserrorCodeMeaning
404action_not_foundNo such action in this conversation
409action_not_pendingThe request is no longer open because it was answered already. error.response.error.action_status carries the final state
409action_cancelledCancelled before it was answered (a new message withdrew it, a run cancel, the agent's timeout policy). action_status is cancelled
410action_expiredThe approval request ran out of time
403action_forbiddenThis caller may not answer (the Console's agent.approve permission, or the agent's approvers setting on a Console without the permission engine)
503authorization_unavailableThe Console could not decide whether this caller may answer (nothing changed; retry after Retry-After)
400invalid_resolutionThe answer does not fit the action (bad decision, answers, approved_args)
409pending_actionA new message was sent while approvals/questions are open. error.response.error.pending_action_ids lists them

Files ​

StatuserrorCodeMeaning
403attachments_disabledThe agent takes no files: off for it, or on with no bucket chosen (agents.get(key).attachments.enabled says so in advance). Also raised by responses.create() with input_file / input_image parts
409storage_unavailableThe agent's bucket cannot take a file now (deleted, disabled, or its provider is gone, inactive or not assigned to the project). The message names the bucket
409storage_not_configuredFiles are on but no bucket was chosen (older data); pick one in the agent's Files settings
409too_many_filesThe session already holds the agent's maximum number of files
413file_too_largeOver the agent's file size limit
415unsupported_file_typeType not in the agent's allowed list
429quota_exceededThe tenant's rate or storage quota
404file_not_foundThe file is not on this session (or was deleted or expired)
409markdown_unavailablefiles.content(…, { variant: 'markdown' }) on a file without a text version (a picture, or a conversion that did not succeed)
409bucket_in_useFrom the Files management API: a bucket cannot be deleted or disabled while an agent keeps session files in it (error.response.agents lists them). No call of this SDK raises it

Webhooks ​

StatuserrorCodeMeaning
403forbiddenMissing webhooks.read / webhooks.admin, or creating for a project that is not the token's. error.response.decisionId names the decision
404not_foundNo such endpoint or delivery
409limit_reached50 endpoints per tenant
409endpoint_disabledredeliver on a disabled endpoint
409delivery_pendingredeliver on a delivery that is already queued
503authorization_unavailableThe permission engine could not decide; retry — never an allow

What the SDK retries on its own ​

The HTTP client retries 429, 502, 503 and 504 up to maxRetries (default 3) with exponential backoff, honouring Retry-After up to 30 seconds; a longer Retry-After is thrown with retryAfterMs set so you can reschedule. A server can veto the retry with { error: { retryable: false } } — that is why a synchronous timeout (504) is not retried: re-sending a turn whose tools may already have run would repeat the side effects.

Other statuses — 400, 401, 402, 403, 404, 409, 410, 413, 415 — are thrown at once.

Which errors can I fix by retrying? ​

RetryDo not retry
429 (agent_run_concurrency_limit, quota_exceeded) after a pause, 503 authorization_unavailable, 502/503/504400 (fix the request), 402 budget_reached (raise the budget), 403, 404, 409 action_not_pending / action_cancelled, 410 action_expired, 504 timeout (switch to background: true)
409 agent_run_conflict once the active run ends409 storage_unavailable until the bucket is fixed

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub