Amarsia
API Reference

Errors

Handle REST envelopes, SDK errors, durable-agent conflicts, retries, and multiple-browser result races.

Overview

Use HTTP status for broad handling and the nested detail.code or normalized SDK code for durable-agent decisions. Do not blindly retry state conflicts.

REST envelopes

The API can return an OpenAI-style error, a FastAPI detail string, a validation list, or a structured detail object:

{
  "detail": {
    "code": "action_result_conflict"
  }
}
{
  "detail": [{
    "loc": ["body", "content"],
    "msg": "field required",
    "type": "value_error.missing"
  }]
}

HTTP status handling

StatusMeaningAction
400Invalid body or tool resultCorrect the request
401Missing or invalid API keyFix authentication
403Origin or caller is not allowedCheck security configuration
404Deployment, conversation, or run not foundVerify IDs and ownership
409Current lifecycle conflicts with the requestRefresh state and branch on code
422Request validation failedCorrect field types
429Rate limitedRetry with backoff
5xxServer failureRetry only when the operation is safe

Durable agent errors

CodeStatusMeaningAction
missing_tool_results400Not every pending call has a resultSubmit all pending call IDs together
unknown_call_id400A result references a non-pending callRefresh and rebuild the result set
invalid_tool_result400Output does not match the tool contractFix the output shape
client_action_required409A new turn was attempted while input is pendingResolve pending calls
run_in_progress409A new turn was attempted while a run is activeRefresh until it settles
action_result_conflict409Different output was already accepted for these callsKeep the first accepted result
conversation_completed409The conversation is permanently completedShow read-only state
run_expired409A non-agent client-tool run expiredStart a new turn

An identical retry of an already accepted tool-result set is idempotent. A different retry conflicts, which protects the first accepted result when several browsers are open.

SDK errors

import { AmarsiaSdkError } from "@amarsia/sdk"

try {
  await client.agent.continue()
} catch (error) {
  if (error instanceof AmarsiaSdkError) {
    console.error(error.status, error.code, error.message, error.details)
  }
}
Error nameMeaning
AmarsiaHttpErrorNon-success API response
AmarsiaValidationErrorInvalid SDK input or completed-conversation continuation
AmarsiaConfigurationErrorMissing client, deployment, or conversation context
AmarsiaAbortErrorAborted request or lifecycle
AmarsiaNetworkErrorNetwork failure

The agent controller also stores normalized error data on client.agent.error. Its conflict handling refreshes current state for common concurrent start and result-submission races.

Retry guidance

  • Retry 429, transient 5xx, and network failures with bounded backoff.
  • Retry a tool result only with the exact same call IDs and outputs.
  • Refresh state before responding to 409.
  • Do not retry conversation_completed.
  • After runStatus === "interrupted", call agent.continue() to start a new turn; do not resubmit a changed result.