Amarsia
Client Usage

Error handling

Handle errors safely across SDK, React, and REST API integrations.

Error shape

When something fails, REST responses usually look like one of these:

{
  "error": {
    "type": "invalid_request_error",
    "message": "content is required",
    "param": "content"
  }
}
{
  "detail": "content is required"
}

For full status code and error-type mapping, use API errors reference.

What fields mean

FieldMeaning
typeBroad error category
messageHuman-readable reason
paramWhich input field caused the problem (if available)
codeOptional machine-friendly error code

SDK try/catch

import { AmarsiaSdkError } from "@amarsia/sdk"

try {
  await client.run({
    content: [{ type: "text", text: "Hello" }],
  })
} catch (error) {
  if (error instanceof AmarsiaSdkError) {
    console.error(error.name, error.status, error.code, error.message)
    console.error(error.details)
  } else {
    console.error(error)
  }
}

SDK-thrown validation errors

Some errors happen before the request reaches the API:

  • content is empty or malformed
  • conversation continuation includes variables or meta
  • message history requested without conversation id

Streaming fallback

If streaming fails:

  1. retry once
  2. if still failing, call regular endpoint
  3. show full answer when it completes

This keeps UI reliable.