MarsAI
Sign in Get Started

MarsAI developer guide

Handle model and upstream failures

Recover from temporary failures without treating partial output as complete or replaying side effects blindly.

Reviewed . Checked against the current MarsAI /v1 behavior and published catalog.

Availability is a runtime condition

MarsAI publishes API aliases whose routes can depend on outside model services. A request may fail even when the key and JSON are correct. The catalog describes configured access and capabilities; it is not an uptime promise for every model.

Keep client error handling centered on the HTTP status, structured error body and whether any response content already arrived.

What fallback can and cannot do

A public alias can have more than one eligible route. If an attempt fails before output reaches the client and the failure is safe to retry, MarsAI may select another target under the same public model ID. Private route names and service URLs stay out of the client response.

Fallback cannot combine two generated answers. Once a stream emits content, a later transport failure leaves an incomplete response for the client to mark and display.

Use a small recovery budget

  1. Record the time, endpoint, public model ID, status and request ID when one is present.
  2. For a temporary 429 or 5xx, honor Retry-After and cap attempts.
  3. Correct invalid requests, authentication, access and credit errors before sending them again.
  4. Offer a model change only when the application or user has chosen an alternative.

Streaming needs its own completion state

A stream may stop after your interface has shown part of an answer. Keep that output, mark it incomplete and avoid presenting it as a finished response. Replaying the call can produce different text and can incur another charge when it completes.

javascript
let completed = false;
try {
  for await (const chunk of stream) renderDelta(chunk);
  completed = true;
} finally {
  markMessage(completed ? "complete" : "incomplete");
}

When one model remains unavailable

Confirm the exact public model ID, check the catalog and try later if the error is temporary. If it persists, send support the model ID, endpoint, time and safe error fields. Remove credentials and prompt content first.