Action result variables
After theai-gateway action runs, detailed results are available in ${actions.ngrok.ai_gateway}. This includes:
- Model selection process and filtering steps
- Every model and request attempted
- API key selection details
- Token counts
- Latency measurements
- Error details for failed attempts
Schema
Overall outcome of the action:
"success" or "error".Error details, only present if status is
"error".code- Error code (for example,"ERR_NGROK_3807")message- Error message describing the failure
Information about the client request.
method- HTTP method from the client requestpath- Request path from the clientrequest_headers- Client request headers (API key/auth headers trimmed)user_agent- User-Agent header from the clientmodel- Client-requested model fieldmodels- Client-requested models fieldapi_key_hash- Trimmed API key from the clientrejected_models- Models the client requested but were excluded (each withmodelandreason)
Estimated input token count calculated by ngrok (used for billing).
Estimated output token count calculated by ngrok (used for billing).
Time added by gateway logic in milliseconds. Excludes time the gateway spent waiting on the upstream to respond to requests.
Details about the model selection process (if applicable). Each entry contains:
strategy- The resolved strategy expressionerror- Error if strategy evaluation failedcandidates_returned- Models that the strategy returnedcandidates_after_allowed_filter- Above list of models after ones that are not allowed by the gateway config have been removed.candidates_after_client_filter- Above list of models after filtering out ones that the client did not want (if applicable).models_to_try- Final list of models to try
Models attempted in chronological order. Each entry contains:
model- Model identifierprovider- Provider identifierauthor- Author identifier (may be empty)api_key_selection- Details about API key selection (strategy, error, keys_to_try)requests_made- Array of request attempts for this model
List of requests made for a specific model. Each request contains:
status- Request outcome:"success"or"error"error- Error message if request failedupstream_input_tokens- Input tokens counted by the providerupstream_output_tokens- Output tokens counted by the providerrequest-urlandapi_keyof the request made to the upstream. Api key is trimmed to avoid leaking.response-status_code,headers,body_on_errorcapture details of the response.upstream_latency- Latency measurements (time_to_first_byte_ms,total_ms)
Details of the successful model, only present when status is
"success".model_index- Index into models_tried array for the successful modelrequest_index- Index into requests_made array for the successful requestmodel- Model id used in the successful requestprovider- Provider id used in the successful requestauthor- Author id used in the successful request (may be empty)
Accessing action results
To access action results, configureon_error: "continue" so subsequent actions can inspect the data:
Cloud Endpoints require a terminal action such as
deny, custom-response, redirect, or forward-internal to complete the request. See Cloud Endpoints for more details.Debugging patterns
Return results as response (development)
During development, return the full action result to the client for inspection:Send to log exports (production)
In production, send action results to your logging infrastructure:Combined approach
Log the results and return a user-friendly error:Interpreting results
Identifying rate limits
Look forstatus_code: 429 in request responses:
api_key_selection.
Identifying model filtering issues
When you getERR_NGROK_3804 or want to understand what the gateway did, check model_selection to understand how models were filtered:
client.model and adjust your configuration or the client request. Model names/spelling may be wrong. Try adding the provider prefix for new models or models not in the gateway config or model catalog.
Identifying timeout issues
Look for attempts without astatus_code or with timeout errors:
per_request_timeout or investigate provider latency using upstream_latency metrics.
Understanding latency
Use the latency measurements to identify bottlenecks:time_to_first_byte_ms/total_ms indicates slow provider response. High gateway_latency_ms indicates gateway processing overhead. Increase per_request_timeout/total_timeout or investigate provider latency.