Loading...
Loading...
Monitors AI Gateway traffic, costs, latency, errors, and token usage by querying request traces via the spans query API.
npx skill4agent add truefoundry/tfy-gateway-skills ai-monitoring<objective>Routing note: For ambiguous user intents, use the shared clarification templates in references/intent-clarification.md.
tracingai-gatewaylogsstatusstatusTFY_BASE_URLTFY_API_KEYTFY_API_SHscripts/tfy-api.shreferences/tfy-api-setup.md| Parameter | Description |
|---|---|
| Fully qualified name of the tracing project, e.g. |
| Data routing destination name, e.g. |
"dataRoutingDestination": "default"POST /api/svc/v1/spans/query# Set the path to tfy-api.sh for your agent (example for Claude Code):
TFY_API_SH=~/.claude/skills/truefoundry-ai-monitoring/scripts/tfy-api.sh
# Basic query: recent spans in the last 24 hours
$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"endTime": "2026-03-27T00:00:00.000Z",
"dataRoutingDestination": "default",
"limit": 50,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"limit": 20,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"filters": [
{"spanAttributeKey": "tfy.span_type", "operator": "eq", "value": "LLM"}
],
"limit": 200,
"sortDirection": "desc"
}'spanAttributesgen_ai.usage.costtfy.request_costgen_ai.usage.input_tokensgen_ai.usage.output_tokens$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"filters": [
{"spanFieldName": "statusCode", "operator": "eq", "value": "ERROR"}
],
"limit": 50,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"filters": [
{"spanAttributeKey": "tfy.span_type", "operator": "eq", "value": "LLM"}
],
"limit": 200,
"sortDirection": "desc"
}'spanAttributes$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"createdBySubjectSlugs": ["user@example.com"],
"limit": 50,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"createdBySubjectTypes": ["virtualaccount"],
"limit": 50,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"filters": [
{"spanAttributeKey": "tfy.span_type", "operator": "eq", "value": "MCP"}
],
"limit": 50,
"sortDirection": "desc"
}'"value": "MCPGateway"$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"applicationNames": ["tfy-llm-gateway"],
"limit": 50,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"filters": [
{"spanFieldName": "spanName", "operator": "contains", "value": "completions"}
],
"limit": 50,
"sortDirection": "desc"
}'$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"filters": [
{"gatewayRequestMetadataKey": "tfy_gateway_region", "operator": "eq", "value": "US"}
],
"limit": 50,
"sortDirection": "desc"
}'| Field | Type | Required | Description |
|---|---|---|---|
| string (ISO 8601) | Yes | Start of time range |
| string (ISO 8601) | No | End of time range (defaults to now) |
| string | One of this or | Tracing project FQN |
| string | One of this or | Data routing destination |
| string[] | No | Filter by trace IDs |
| string[] | No | Filter by span IDs |
| string[] | No | Filter by parent span IDs |
| string[] | No | Filter by subject type ( |
| string[] | No | Filter by subject slug (e.g. email) |
| string[] | No | Filter by application name |
| integer | No | Max results (default 200) |
| string | No | |
| string | No | Pagination token from previous response |
| array | No | Array of filter objects (see Filter Types) |
| boolean | No | Include feedback data |
{"spanFieldName": "<field>", "operator": "<op>", "value": "<val>"}spanNameserviceNamespanKindstatusCode{"spanAttributeKey": "<key>", "operator": "<op>", "value": "<val>"}spanAttributestfy.span_typegen_ai.usage.cost{"gatewayRequestMetadataKey": "<key>", "operator": "<op>", "value": "<val>"}X-TFY-LOGGING-CONFIGeqneqcontainsnot_containsstarts_withends_with{
"data": [
{
"spanId": "...",
"traceId": "...",
"parentSpanId": "...",
"serviceName": "tfy-llm-gateway",
"spanName": "POST https://api.openai.com/v1/chat/completions",
"spanKind": "Client",
"scopeName": "...",
"scopeVersion": "...",
"timestamp": "2026-03-26T14:30:00.000Z",
"durationNs": 1234567890,
"statusCode": "OK",
"statusMessage": "",
"spanAttributes": {
"gen_ai.usage.input_tokens": 150,
"gen_ai.usage.output_tokens": 80,
"gen_ai.usage.cost": 0.0023,
"tfy.request_cost": 0.0023,
"tfy.span_type": "LLM"
},
"events": [],
"createdBySubject": {
"subjectId": "...",
"subjectSlug": "user@example.com",
"subjectType": "user",
"tenantName": "my-tenant"
},
"feedbacks": []
}
],
"pagination": {
"nextPageToken": "..."
}
}pagination.nextPageTokenpageToken$TFY_API_SH POST '/api/svc/v1/spans/query' '{
"startTime": "2026-03-26T00:00:00.000Z",
"dataRoutingDestination": "default",
"limit": 200,
"pageToken": "TOKEN_FROM_PREVIOUS_RESPONSE"
}'nextPageTokenRecent Gateway Requests (last 24h):
| Time | Model | Status | Tokens (in/out) | Cost | Latency | User |
|---------------------|----------------|--------|-----------------|----------|-----------|-------------------|
| 2026-03-26 14:30:00 | openai/gpt-4o | OK | 150 / 80 | $0.0023 | 1.23s | user@example.com |
| 2026-03-26 14:29:55 | anthropic/... | OK | 200 / 120 | $0.0045 | 2.10s | bot@svc |
| 2026-03-26 14:29:30 | openai/gpt-4o | ERROR | 100 / 0 | $0.0000 | 0.45s | user@example.com |Cost Summary (last 24h):
| Model | Requests | Total Cost | Avg Cost/Req | Total Tokens |
|--------------------|----------|------------|--------------|--------------|
| openai/gpt-4o | 142 | $3.21 | $0.023 | 45,200 |
| anthropic/claude | 58 | $1.87 | $0.032 | 22,100 |
| Total | 200 | $5.08 | $0.025 | 67,300 |durationNsdataRoutingDestinationtracingProjectFqnstatusai-gatewaytracinglogsaccess-tokensMissing required parameter. Ensure you provide either:
- "tracingProjectFqn": "tenant:tracing-project:name"
- "dataRoutingDestination": "default"
And a valid "startTime" in ISO 8601 format.Authentication failed. Run the status skill to verify your TFY_API_KEY is valid.Empty results. Check:
- Time range is correct (startTime/endTime)
- The dataRoutingDestination or tracingProjectFqn exists
- Filters are not too restrictive (try removing filters first)
- Gateway has actually received requests in this time periodIf a pageToken returns an error, restart the query from the beginning
with a fresh request (no pageToken).