Skip to main content
When interacting with the Gloo AI API, error handling depends on whether the response is non-streaming or streaming. For non-streaming responses, check the HTTP status code and parse the JSON response body. For streaming Completions responses, the initial response is 200 text/event-stream; once streaming has started, later failures are delivered as Server-Sent Events instead of non-2xx HTTP responses. For AI error objects, error.code is the numeric internal code, such as 2001, and error.name is the symbolic code, such as PROVIDER_TIMEOUT.

Quick Reference

HTTP Status Codes

Full table of every HTTP status returned by active endpoints.

Error Code Reference

Exact error codes from the API with resolution guidance.

AI Error Object

Field reference for enriched Completions errors.

Streaming Errors

How errors are delivered after an SSE stream has started.

Authentication Errors

401 and 403 errors — missing tokens, expired credentials, permission issues.

Rate Limiting

Spending limits, endpoint quotas, and streaming provider rate limits.

Endpoint-Specific Errors

Error details for Completions, Ingestion, Content Controls, and Search.

Best Practices

Patterns for reliable error handling across all endpoints.

HTTP Status Codes


Error Code Reference


AI Error Object

Completions errors include an enriched top-level error object. Use it for programmatic handling instead of parsing human-readable messages.
Use error.retryable for retry decisions, error.name or error.code for branching, and trace_id for debugging with support.
Hitting persistent inference issues? If model inference keeps failing — for example a repeating 2013 / PROVIDER_INFERENCE_ERROR or 3001 / INTERNAL_ERROR — open a ticket with us at hello@gloo.us and include the trace_id from the error response. The trace_id lets us look up the exact request and resolve the issue faster.

Common Error Scenarios

Authentication Errors

These errors occur when there is an issue with your API key or the permissions associated with it.

401 Unauthorized — Missing or Invalid API Key

Returned when the Authorization header is missing from the request.
Some Completions endpoints may return an app-level response:
Search endpoints can be rejected earlier by the gateway. When the Authorization header is present but malformed or the API key is invalid, the gateway returns 403 with the forbidden code.

403 Forbidden — Insufficient Permissions

Returned when the request includes authorization, but the caller does not have permission for the requested resource or publisher, or the gateway rejects the authorization header.
For the Ingestion API, a 403 most commonly means the publisher_id doesn’t belong to your organization, or the item you are referencing does not belong to the specified publisher.

Validation Errors (400 / 422)

These errors indicate a problem with the parameters or body of your request. 400 Bad Request signals a structurally invalid request, while 422 Unprocessable Entity signals valid JSON that fails field-level validation.

Missing Required Field

Returned when a required body field is absent. Example: model is required when specifying direct model routing for Completions V2.

Invalid Routing Configuration

Completions V2 returns this as 400 when more than one — or no — routing mechanism is specified.

Invalid Data Type

Returned when a field receives a value of the wrong type. Example: certainty expects a float.

Resource Not Found (404)

Returned when the requested item does not exist or has been permanently deleted.
Publisher not found and invalid collection cases return 400, not 404. See Ingestion and Search & Recommendations for these examples.

Duplicate Upload Results

Duplicate Content (Ingestion)

When files are submitted that were already ingested, the API returns 200 OK with a duplicates array in the response body — this is not an HTTP error.
Duplicates are returned in the response body, not as a 409 Conflict error.

Rate Limiting (429)

An HTTP 429 can represent a Completions spending limit or an endpoint-specific request quota. These conditions do not share one response format or retry policy. For Completions endpoints, a spending-limit response has the following shape:
SPENDING_LIMIT_EXCEEDED is not retryable and does not include Retry-After. Retry only after the account’s spending-limit condition is resolved. Endpoint-specific quotas can also return HTTP 429. Their error bodies and headers vary by endpoint. Honor Retry-After when it is present; do not assume that every response includes X-RateLimit-Limit, X-RateLimit-Remaining, or X-RateLimit-Reset. An upstream provider rate limit that occurs after a Completions stream starts is not an HTTP 429. It is delivered inside the HTTP 200 stream as a 2004 / RATE_LIMIT SSE error event. Use error.retryable to decide whether to retry.
See Rate Limits for response-specific retry guidance and pseudocode.

Server Errors (5xx)

Retry only transient failures. For Completions errors, check error.retryable; in particular, do not retry 1005 / SPENDING_LIMIT_EXCEEDED. For endpoint-specific 429 responses, honor Retry-After when present and follow the endpoint’s documented behavior.

500 Internal Server Error

An unexpected error occurred on the Gloo platform or during model inference. Retry with exponential backoff.

502 Bad Gateway

Returned by Content Controls endpoints when a vector-store update fails in the underlying data store.

503 Service Unavailable

The upstream provider or backing service is temporarily unavailable. Retry with exponential backoff.

Streaming Errors

When stream=true on Completions endpoints, the response starts as 200 text/event-stream. After the SSE headers have been sent, the API cannot change the HTTP status code. Stream-time failures are therefore sent as SSE events. A stream error event has choices[0].finish_reason set to "error" and includes the same enriched top-level error object used by non-streaming Completions errors.
Stream-time error scenarios include provider timeout, provider rate limit, provider 5xx, provider bad request, provider auth failure, routing error, unsupported model, empty stream, provider unavailable, malformed provider SSE, connection drop, and internal platform error.
If a stream error event includes error.retryable: true, retry with exponential backoff. If error.retryable is false, retry only after changing the request or model selection.
For retry ceilings, application-level continuation after partial output, and the UX decisions around interrupted streams, see Handling Streaming Failures.

Content Filter During Streaming

Content moderation during streaming is represented differently from other stream errors. It does not emit a top-level error object. Instead, the stream sends a final assistant content event and then a terminal event with finish_reason: "content_filter".
Do not retry content-filter terminations unchanged. Adjust the user-facing workflow or request content.

Grounded Streaming Citations

For Grounded Completions, when stream=true, include_citations=true, and citations are available, the first SSE event may contain a citations array before model content begins. This is a normal 200 stream event, not an error.

Endpoint-Specific Errors

Completions V2

Completions V2 Reference

POST /ai/v2/chat/completions
The endpoint reference documents both application/json responses for non-streaming requests and text/event-stream responses for stream=true. Invalid Routing Configuration — 400 Specify exactly one of auto_routing, model, or model_family per request.
Invalid Request — 400 Returned when no user message is found in the messages array.
Messages Array Missing — 422 The messages field is required. An absent messages array returns a validation error.
Context Window Exceeded — 400
Provider Timeout — 408
Provider Content Filter — 422
Provider Inference Error — 500
Provider Unavailable — 503

Grounded Completions

Grounded Completions Reference

POST /ai/v2/chat/completions/grounded
Grounded Completions inherits all Completions V2 error responses, including routing configuration errors, context length exceeded, provider timeout, content filter, inference error, and provider unavailable. The endpoint reference documents both application/json responses for non-streaming requests and text/event-stream responses for stream=true. For streaming grounded responses, citations may be emitted as the first stream event when include_citations=true. No Relevant Content Retrieved — 200 Zero results is not an error — it means no retrieved content exceeded the certainty threshold. The response returns 200 OK with "sources_returned": false. Lower certainty toward 0.5 or verify that content has been ingested.

Ingestion

Ingestion V2 Reference

POST /ingestion/v2/files
Publisher Not in Organization — 403 Returned when the item or publisher does not belong to your organization.
Missing Authorization — 401 Returned by the gateway when the Authorization header is missing.
Publisher Not Found — 400
Producer ID with Multiple Files — 400
File Read Error — 400
Duplicate Content — 200 Response Duplicate files appear in the duplicates array of a successful 200 OK response, not as an HTTP error. See Duplicate Upload Results.

Content Controls (Data Engine)

Single Item Patch

PATCH /engine/v2/item

Multi-Item Patch

PATCH /engine/v2/items

Delete Items

DELETE /engine/v2/items

Get Item Metadata

GET /engine/v2/items/

Get Item by Producer ID

POST /engine/v2/publisher//items/by-producer
Item Not Found — 404
For items looked up by producer_id:
Publisher Not Found — 400
Publisher / Item Ownership Mismatch — 403
Unauthorized delete attempt:
Vector-Store Update Failure — 502 Returned by the single-item PATCH endpoint when the vector store update fails.
Batch / Request Validation — 400 Missing patch operations:
Missing item IDs in a delete request:
Missing producer IDs:

Search & Recommendations

Search

POST /ai/v1/data/search

Recommendations

POST /ai/v1/data/items/recommendations/base
Invalid Collection — 400
Missing or Invalid Tenant — 400
For multi-tenant collections where tenant is omitted:
Missing Authorization — 401 Returned by the gateway when the Authorization header is missing.
Invalid Authorization — 403 Returned by the gateway when the Authorization header is present but malformed or the API key is invalid.
Validation Errors — returned as 403 Empty query, empty collection, and invalid limit values return HTTP 403 rather than 422. Don’t treat these as permission errors — they indicate an invalid request body. Empty query:
Invalid limit:
Zero results is not an error — it means no content exceeded the certainty threshold. Lower certainty toward 0.5 or verify that content has been ingested.

Error Handling Best Practices

Log error.name and error.code, not just the status — Status codes tell you the category; the symbolic name and numeric code tell you exactly what went wrong. Log them in your error handler for precise alerting and debugging. Use error.retryable for Completions retries — For non-streaming responses, use the HTTP status plus error.retryable. For streaming responses, inspect stream error events and use error.retryable. Some failures happen inside an HTTP 200 stream after headers have been sent. Retry only transient failures408 provider timeouts and retryable 5xx failures are candidates for bounded retries. A 429 is not automatically retryable: 1005 / SPENDING_LIMIT_EXCEEDED requires the limit condition to be resolved, while an endpoint-specific quota may provide Retry-After. Use exponential backoff for retries — Wait (2^attempt) + jitter between retries, up to 5 attempts for non-streaming requests. Live streaming needs much lower ceilings — see Handling Streaming Failures for streaming retry budgets and Rate Limits for pseudocode. Use detail to pinpoint validation failures — For 422 responses, the detail array tells you exactly which field failed: loc is the field path, msg is the reason, and input is the value you sent. Open a ticket with the trace_id for persistent inference issues — If inference errors continue after retrying with backoff, contact us at hello@gloo.us and include the trace_id returned in the error response. The trace_id lets us trace the exact request and resolve the issue faster.