How do I troubleshoot a Leiolai API error?

Read the Leiolai response’s HTTP status, error code, and X-Request-Id. A 401 points to authentication, a 402 to balance or budget, and a mode restriction can produce 403. A 400 identifies an invalid request. For a streaming response, continue reading events: an error can arrive after HTTP 200.

What should I check for HTTP 401?

invalid_api_key means the request did not provide a valid Leiolai key. Check the key value and authentication header. OpenAI-format requests use Authorization: Bearer; Messages uses x-api-key with the required version header. Leave keys out of diagnostic screenshots and shared logs.

Key creation and authentication

What should I check for HTTP 402?

Read the specific code. insufficient_credits means the Leiolai account needs balance. api_budget_exhausted means a key or account budget has reached its limit. api_budget_required means auto reload is enabled and API use needs a budget. Update the relevant account control rather than repeatedly sending the same request.

Why can a request return HTTP 403?

api_key_mode_restricted means the requested Leiolai mode conflicts with the key’s permission. Use the mode allowed by that key or create a key for the intended mode. Content-policy errors can also return 403; check the code before changing a key restriction.

Match the request to the key restriction

What causes HTTP 400?

Check the field identified in the Leiolai error. A 400 can result from missing mode on an Unrestricted key, unsupported fields, invalid JSON, conflicting values, malformed tool schemas or results, or context_length_exceeded. Correct that field and retry the request.

Check structured-output fields Check tool definitions and results

What should I check for a model or session not found error?

For model_not_found, use the current model ID leiolai-1. For session_not_found, confirm that the continuous session is still active and that the injection uses the same key that opened the session. A finished session needs a new opening request.

Use the current model identifier

How should I handle rate limits and temporary failures?

For a Leiolai 429 response, wait for the Retry-After interval in seconds. For a temporary 503, retry a limited number of times with increasing delays. Keep the error code and request ID for a support report if the request continues to fail.

Why can an HTTP 200 stream still fail?

After server-sent events begin, the HTTP status stays 200. Read the stream’s named error or failure event and terminal status. Leiolai Responses can send response.failed, and Messages can send an error event. Treat a missing successful terminal signal as an incomplete response.

Read stream completion signals

What information helps when reporting an API problem?

Keep X-Request-Id, the endpoint format, HTTP status, error code, and a redacted request that reproduces the issue. A valid client-provided X-Request-Id can be echoed. Include enough request structure to explain the failure while keeping the Leiolai API key and confidential prompt content private.