For the complete documentation index, see llms.txt. This page is also available as Markdown.

Errors and Debugging

API Errors and Debugging

Error Response Structure

The InteractiveAI Router returns errors in a consistent JSON format:

type ErrorResponse = {
  error: {
    code: number;
    message: string;
    metadata?: Record<string, unknown>;
  };
};

The HTTP status code matches error.code when the error stems from:

  • An invalid request

  • Insufficient credits on your API key or account

Otherwise, the HTTP status is 200 OK, and any error during generation appears in the response body or as an SSE data event.

Handling Errors in Code

const request = await fetch('https://app.interactive.ai/...');
console.log(request.status); // Will be an error code unless the model started processing your request
const response = await request.json();
console.error(response.error?.status); // Will be an error code
console.error(response.error?.message);

Error Codes

Code
Description

400

Bad Request: invalid or missing parameters, CORS issues

401

Unauthorized: expired OAuth session, disabled or invalid API key

402

Payment Required: insufficient credits. Add funds and retry.

403

Forbidden: input flagged by moderation

408

Request Timeout: request exceeded time limit

429

Too Many Requests: rate limit exceeded

502

Bad Gateway: model unavailable or returned invalid response

503

Service Unavailable: no provider meets your routing requirements

Moderation Errors

When content is flagged, error.metadata provides details:

Provider Errors

When a provider encounters an error, error.metadata contains:

Empty Responses

The model may occasionally return no content. Typical causes:

  • Cold start initialization periods

  • Infrastructure scaling to handle load

Warm-up times range from seconds to several minutes depending on the model and provider.

For persistent issues, implement retry logic or switch to a different provider or model with recent activity.

Upstream providers may charge for prompt processing even when no content is generated.

Streaming Error Formats

Streaming mode (stream: true) handles errors differently based on timing.

Pre-Stream Errors

Errors occurring before any tokens are sent follow the standard format with appropriate HTTP status codes.

Mid-Stream Errors

Errors after streaming begins arrive as SSE events with a unified structure:

Example SSE data:

Key characteristics:

  • Error appears at the top level alongside standard fields

  • choices array with finish_reason: "error" terminates the stream

  • HTTP status remains 200 OK since headers were already sent

  • Stream ends after this event

Responses API Error Events

The Responses API (/api/alpha/responses) uses typed events for streaming errors:

  1. response.failed - Official failure event

  2. response.error - Error during response generation

  3. error - Plain error event (undocumented but sent by OpenAI)

Error Code Transformations

The Responses API converts certain errors into successful completions:

Error Code
Transformed To
Finish Reason

context_length_exceeded

Success

length

max_tokens_exceeded

Success

length

token_limit_exceeded

Success

length

string_too_long

Success

length

This allows graceful handling of limit-based errors without treating them as failures.

API-Specific Error Handling

Chat Completions API (/api/v1/chat/completions)

  • No tokens sent: Returns standalone ErrorResponse

  • Some tokens sent: Embeds error in the final response's choices array

  • Streaming: Errors delivered as SSE events with top-level error field

Responses API (/api/alpha/responses)

  • Error transformations: Certain errors become successful responses with appropriate finish reasons

  • Streaming events: Uses typed events (response.failed, response.error, error)

  • Graceful degradation: Handles provider-specific errors with fallback behavior

Error Type Definitions

Debugging

The InteractiveAI Router provides a debug option that reveals the exact request body sent to the upstream provider. This helps you understand how your parameters are transformed for different providers.

Debug Option Schema

Enabling Debug Output

Add the debug parameter to your request:

Debug Response Format

With debug.echo_upstream_body enabled, the first streaming chunk contains an empty choices array and a debug field with the transformed request:

Constraints

Streaming Only: Debug output works exclusively with streaming requests (stream: true) on the Chat Completions API. Non-streaming requests and Responses API requests ignore the debug parameter.

Development Use Only: Do not enable debug mode in production. It may expose sensitive request data that should remain private.

Use Cases

Debug output helps with:

  1. Inspecting Parameter Transformations: Observe how the Router converts your parameters into provider-specific formats, including max_tokens handling and temperature mapping.

  2. Validating Message Formatting: Review how the Router structures and combines messages for each provider, such as system message concatenation or user message merging.

  3. Identifying Applied Defaults: Discover which default values the Router injects when you omit parameters from your request.

  4. Troubleshooting Provider Fallbacks: When fallbacks are configured, a debug chunk is emitted for each provider attempt, letting you trace which providers were contacted and what payload each received.

Last updated

Was this helpful?