camelAI Documentation

API Reference

Errors

HTTP errors, failed runs, and tool calls that did not complete

There are three kinds of failure:

  1. The API refused a request. An HTTP status and a JSON body. The SDKs throw AgentError with status and code.
  2. A run failed. The request was accepted, and the run ended badly. The SDKs' run() throws RunError with the run, unless throwOnError: false.
  3. A tool call didn't complete within a run that otherwise went on. The model was told, and the run lists it in toolErrors. Nothing throws.

HTTP errors

Error bodies are {"error": "<message for people>", "code": "<CODE>"}. The message may change and the code won't, so switch on code. New codes may be added; treat an unknown one by its status. Every 429 and 503 has Retry-After, and the SDKs honor it and retry.

StatuscodeMeaningWhat to do
400INVALID_REQUESTMalformed or invalid; the message says howFix the request
400INVALID_HISTORYAn imported initialMessages has a message it can't takeFix the named message
401UNAUTHORIZEDNo valid token, or an expired browser tokenSend a valid key; mint a new browser token
402SPEND_LIMITThe agent's spend limit, or the account's monthly capRaise the limit
402INSUFFICIENT_CREDITThe account's prepaid credit is spentAdd credit in the console
403FORBIDDENThe token may not do this, such as a browser token outside its agentUse your API key, server-side
404NOT_FOUNDNo such agent, request, input or other resource in your accountCheck the id
409IDEMPOTENCY_CONFLICTThe Idempotency-Key or request id was used for another requestUse a new key for a new request
409IDEMPOTENCY_IN_PROGRESSThe first request with this key is still runningRetry shortly
409APPLICATION_CONNECTEDAnother process serves this agent's toolsClose it, pass takeover: true, or connect with attach: false
409APPLICATION_NOT_CONNECTEDThe agent's tools need their process and none is connectedStart it, serve tools over HTTP, or pass allowDisconnected: true
409REPLAY_GAPThe Last-Event-ID is behind the replay bufferReconnect with ?snapshot=1 and read /state
409CONFLICTAnother conflict, named in the messageSee below
410GONEThe agent was deleted or expiredUpsert the key again for a fresh agent
413TOO_LARGEThe request body is too largeUpload large files first and attach them by path
413HISTORY_TOO_LARGEAn imported history is over 16 MBSend recent messages after a compactionSummary
429RATE_LIMITEDToo many agents awake, requests queued, or subscribersRetry after Retry-After
503UNAVAILABLEA node is draining or starting, or an agent is movingRetry after Retry-After; nothing happened
500INTERNALA bugRetry, and report it with the request id

Common CONFLICT cases:

  • An existing agent's subject, context, definition or mounts can't change. An upsert of an existing key changed a field that's set only at creation. Delete the agent or use another key.
  • This input is already answered. Someone answered first. The body's input says how it settled. Answering again the same way is a 200.
  • The definition is at revision N, not M. A definition update with a stale revision. Read it again and retry.

Run failures

RunError.codeMeaning
model_errorThe model provider refused or failed after 3 retries for transient failures: a bad request, an invalid key, refused content, or a context overflow compaction couldn't fix
spend_limitThe agent's spend limit (or the account's cap) stopped the turn after the response that crossed it. Raise the limit and send the next message
runtime_errorcamelRun couldn't carry out the run: for example, the model has no key, or the agent was deleted

A run with uncertain: true was cut short by a restart where it couldn't resume. Its tool calls may or may not have taken effect, so check before retrying.

Tool errors

A run lists each tool call that didn't complete as toolErrors: [{tool, toolCallId?, code, outcomeUnknown?, message}]. The model got the same message and carried on.

codeMeaningOutcome unknown
timeoutNo answer or progress within the tool's deadlineYes
connection_lostThe connection closed before the answer arrivedYes
not_connectedNo process served the agent's attached tools, so the call didn't runNo
source_unavailableIts MCP server couldn't be reached, listed or authenticated withNo
failedAnything else that kept it from runningNo

A tool that ran and reported its own failure (threw, or answered isError) is not a tool error: that's the tool's answer, which the model reads.

SDK errors

TypeScriptPython
Any failureAgentError: message, status, code, requestId, uncertain, retryAfterMsAgentError: status, code, request_id, uncertain, retry_after
A failed runRunError extends AgentError, with runRunError, with run
Another process took the agent's toolscode: "APPLICATION_REPLACED", through onErrorThe same, through on_error
A served tool's token check failedRuntimeTokenErrorRuntimeTokenError

Stopping a wait (signal, or Python timeout) doesn't stop the run. Wait for it again with the same idempotencyKey.