Skip to main content
The AI Gateway may make several attempts before returning a response. The response alone doesn’t show how many attempts were made. This guide shows you how to use a response header to find each attempt and see what happened.

1. Read the attempt count off the response

Every response through ngrok.ai includes the Ngrok-AIG-Attempts header, which shows how many attempts were made. A value greater than 1 means the first attempt failed and the gateway tried again.
The AI Gateway made three attempts. The third candidate in the list handled the request after the first two candidates failed.
Use the Ngrok-AIG-Model response header to identify the model that handled your request. The AI Gateway passes the provider’s response body through unchanged, including its model field. If the gateway switches models after a failed attempt, these values may differ. Use the header as the source of truth.

2. Look the request up by ID

Pass the Ngrok-AIG-Request-Id value to the attempts endpoint:
You get every upstream attempt for that request, ordered by attempt number:
This endpoint lets you only view requests from your account. It cannot modify them. If a request belongs to another account, the endpoint returns “not found” instead of “forbidden.”

3. Check why the AI Gateway retried or stopped

For each attempt, check completion to see how it ended and retryAction to see what the AI Gateway decided to do next. Use served to identify the attempt that returned the response to your client.

Identify the attempt that returned the response

Look for served: true. At most one attempt per request has this value. Do not assume the last attempt returned a response. A request can end with a failed attempt that did not produce a response for your client.

Check how each attempt ended

The completion field has one of these values:
  • succeeded
  • failed
  • timed_out
  • stream_failed
  • unknown
For failed attempts, read the error details to find the cause, then check retryAction to understand why the gateway retried or stopped.

Follow the retry decisions

retryAction is optional. It is absent from attempts recorded before the gateway began storing retry decisions. In the example above, next_key on attempt 1 means the gateway tried another key for the same provider. next_backend on attempt 2 means it then moved to the next model in the failover list. Check each attempt’s error details to see why it failed.

What this tells you to change

What this endpoint does not include

This endpoint does not include captured request and response bodies, which could contain sensitive information.

Next steps

Handle gateway errors

How failover decides what to try next

Debug failed requests

Diagnose a failure from the response alone