{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usdf-fi/json-schema/usdf-fi-request-detail-schema.json",
  "title": "RequestDetail",
  "description": "One request of the caller's: its usage row, how it ran, and for the signed-in owner its logged texts.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usdf-fi-openapi.json#/components/schemas/RequestDetail",
  "type": "object",
  "properties": {
    "object": {
      "type": "string",
      "const": "request"
    },
    "id": {
      "type": "string",
      "description": "The request's id (its answer's id, x-request-id)."
    },
    "request_id": {
      "type": "string"
    },
    "usage_id": {
      "type": "string",
      "description": "Its usage row's id (the activity's id)."
    },
    "created_at": {
      "type": "string",
      "description": "When it was recorded.",
      "format": "date-time"
    },
    "key": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "label": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "prefix": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "model": {
      "type": "string",
      "description": "The model charged."
    },
    "provider": {
      "type": "string",
      "description": "The kind of route that served: hosted, network (Network compute) or private (attested hardware); never the provider's name."
    },
    "upstream": {
      "anyOf": [
        {
          "type": "string",
          "description": "The same kind, kept for the shape: a source behind the route is of its kind."
        },
        {
          "type": "null"
        }
      ]
    },
    "endpoint": {
      "type": "string"
    },
    "stream": {
      "type": "boolean"
    },
    "batch": {
      "type": "boolean"
    },
    "status": {
      "type": "string",
      "enum": [
        "ok",
        "partial",
        "failed_refunded"
      ]
    },
    "reason": {
      "anyOf": [
        {
          "type": "string",
          "description": "Why a refunded request was refunded (upstream_error, upstream_timeout, empty_output, caller_cancelled, ...); cache_hit on an answer from the response cache."
        },
        {
          "type": "null"
        }
      ]
    },
    "finish_reason": {
      "anyOf": [
        {
          "type": "string",
          "description": "The answer's finish reason as the provider gave it (stop, length, tool_calls, content_filter, ...), where the request's detail recorded one."
        },
        {
          "type": "null"
        }
      ]
    },
    "usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "integer"
        },
        "completion_tokens": {
          "type": "integer"
        },
        "cached_tokens": {
          "type": "integer",
          "description": "Prompt tokens read from the provider's cache, among prompt_tokens."
        },
        "total_tokens": {
          "type": "integer"
        }
      }
    },
    "cost": {
      "type": "object",
      "description": "Where the money came from. A platform's sub-key reads the total alone.",
      "properties": {
        "total": {
          "$ref": "#/$defs/Amount",
          "description": "What the request was paid with in all."
        },
        "charged": {
          "$ref": "#/$defs/Amount",
          "description": "From the balance."
        },
        "free_credit": {
          "$ref": "#/$defs/Amount",
          "description": "From free credit."
        },
        "markup": {
          "$ref": "#/$defs/Amount",
          "description": "A platform's markup on its sub-key's request."
        },
        "uncharged": {
          "$ref": "#/$defs/Amount",
          "description": "What the usage cost that was not charged (a balance or a budget that ran short)."
        },
        "refunded": {
          "anyOf": [
            {
              "$ref": "#/$defs/Amount",
              "description": "What went back to the balance, on a refunded request."
            },
            {
              "type": "null"
            }
          ]
        },
        "price_version": {
          "anyOf": [
            {
              "type": "string",
              "description": "The price sheet it was charged at."
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "total",
        "refunded"
      ]
    },
    "efficiency": {
      "anyOf": [
        {
          "$ref": "#/$defs/Efficiency",
          "description": "Null on a refunded request. at_source_price is at the model's source price now, null once the sheet the request was priced at is no longer in force; tokens_per_watt is the model's estimate (null for a request a network node served)."
        },
        {
          "type": "null"
        }
      ]
    },
    "latency": {
      "type": "object",
      "properties": {
        "total_ms": {
          "anyOf": [
            {
              "type": "number",
              "description": "The gateway's wall time for the request."
            },
            {
              "type": "null"
            }
          ]
        },
        "ttft_ms": {
          "anyOf": [
            {
              "type": "number",
              "description": "To the first output, from the request's arrival (streams)."
            },
            {
              "type": "null"
            }
          ]
        },
        "generation_ms": {
          "anyOf": [
            {
              "type": "number",
              "description": "From the first output (or the upstream request) to its last byte."
            },
            {
              "type": "null"
            }
          ]
        },
        "overhead_ms": {
          "anyOf": [
            {
              "type": "number",
              "description": "What the gateway itself added."
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "route": {
      "anyOf": [
        {
          "type": "object",
          "description": "The route that served and why, as the receipt's router gave it.",
          "properties": {
            "provider": {
              "type": "string",
              "description": "The kind of route: hosted, network or private."
            },
            "route": {
              "type": "string",
              "description": "The route's model id."
            },
            "route_type": {
              "type": "string",
              "description": "direct, book or provider."
            },
            "mode": {
              "type": "string",
              "description": "cheapest, fastest, reliable or the service tier asked for."
            },
            "why": {
              "type": "string",
              "description": "cheapest, fastest, reliable, fallback or only_route; ordered where provider.order named it."
            },
            "fallback": {
              "type": "string",
              "description": "on or off."
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "attempts": {
      "type": "array",
      "description": "Every route tried, in order. Empty where the request's detail recorded none.",
      "items": {
        "type": "object",
        "properties": {
          "provider": {
            "type": "string",
            "description": "The kind of route tried: hosted, network or private."
          },
          "route": {
            "type": "string"
          },
          "outcome": {
            "type": "string",
            "description": "served: it served the answer; failed: it answered an error or was unreachable, and the request moved on or ended; ended: the request ended on it without an answer (the deadline, a shutdown, the caller gone).",
            "enum": [
              "served",
              "failed",
              "ended"
            ]
          },
          "status": {
            "anyOf": [
              {
                "type": "integer",
                "description": "The provider's HTTP status, where it answered one."
              },
              {
                "type": "null"
              }
            ]
          },
          "code": {
            "anyOf": [
              {
                "type": "string",
                "description": "The kind of failure: route, account or client."
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "provider",
          "route",
          "outcome"
        ]
      }
    },
    "fallbacks": {
      "type": "integer",
      "description": "How many routes failed before the one that served."
    },
    "models": {
      "anyOf": [
        {
          "type": "object",
          "description": "For a request that named fallback models: the models named, the one that served, and each passed over before it.",
          "properties": {
            "requested": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "served": {
              "type": "string"
            },
            "passed_over": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "status": {
                    "type": "integer"
                  },
                  "code": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "chosen": {
      "anyOf": [
        {
          "type": "object",
          "description": "How the model was chosen, where the request named a router or an alias.",
          "properties": {
            "via": {
              "type": "string",
              "description": "auto, auto:cost, auto:tools, free or alias."
            },
            "requested": {
              "type": "string"
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "preset": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "slug": {
              "type": "string"
            },
            "version": {
              "type": "integer"
            },
            "pinned": {
              "type": "boolean",
              "description": "The request named this version (@preset/{slug}@{version})."
            }
          },
          "required": [
            "slug",
            "version"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "tier": {
      "anyOf": [
        {
          "type": "string",
          "description": "The service tier asked for."
        },
        {
          "type": "null"
        }
      ]
    },
    "served_tier": {
      "anyOf": [
        {
          "type": "string",
          "description": "The service tier the provider says it served."
        },
        {
          "type": "null"
        }
      ]
    },
    "cache": {
      "anyOf": [
        {
          "type": "string",
          "description": "Answered from the response cache.",
          "enum": [
            "hit"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "private": {
      "anyOf": [
        {
          "type": "string",
          "description": "How a private request was served: attested, or zero_retention_only (before 2026-10-19 only)."
        },
        {
          "type": "null"
        }
      ]
    },
    "byok": {
      "type": "boolean",
      "description": "Served with the account's own provider key."
    },
    "no_logs": {
      "type": "boolean",
      "description": "The key was in no-logs mode: nothing of the prompt or the answer was kept."
    },
    "spent_from": {
      "type": "string",
      "enum": [
        "account",
        "sub_key",
        "org"
      ]
    },
    "settlement": {
      "type": "object",
      "description": "unsettled, none, or its batch, status, transaction, explorer link and rows."
    },
    "detail_recorded": {
      "type": "boolean",
      "description": "Whether the request path's detail (finish reason, timings, attempts, models, route, preset) is here: false for a request it recorded none of (one before it was recorded, an endpoint that records none, a detail past its 90 days)."
    },
    "bodies": {
      "type": "object",
      "description": "The prompt and the response, where the account's request logs kept them (GET /v1/logs/{id} reads the same log).",
      "properties": {
        "available": {
          "type": "boolean"
        },
        "reason": {
          "type": "string",
          "description": "Why they are not shown: an API key reads none (session_only); the key was in no-logs mode; only chat and completions requests are logged; past the logs' 30 days; or the account's request logs did not keep this one.",
          "enum": [
            "session_only",
            "no_logs",
            "not_logged_endpoint",
            "expired",
            "not_kept"
          ]
        },
        "log_id": {
          "type": "string"
        },
        "prompt": {
          "anyOf": [
            {
              "type": "string",
              "description": "The prompt as sent upstream, after redaction: a chat's messages as JSON."
            },
            {
              "type": "null"
            }
          ]
        },
        "response": {
          "anyOf": [
            {
              "type": "string",
              "description": "The answer's text, and its tool calls."
            },
            {
              "type": "null"
            }
          ]
        },
        "prompt_bytes": {
          "type": "integer"
        },
        "response_bytes": {
          "type": "integer"
        },
        "prompt_truncated": {
          "type": "boolean"
        },
        "response_truncated": {
          "type": "boolean"
        },
        "expires_at": {
          "anyOf": [
            {
              "type": "string",
              "description": "When the log is deleted.",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "available"
      ]
    },
    "links": {
      "type": "object",
      "properties": {
        "self": {
          "type": "string"
        },
        "receipt": {
          "type": "string"
        },
        "proof": {
          "type": "string"
        },
        "generation": {
          "type": "string"
        },
        "log": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "note": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "model",
    "status",
    "usage",
    "cost",
    "attempts",
    "bodies"
  ],
  "$defs": {
    "Amount": {
      "type": "object",
      "description": "An amount of USDF: base units (1 unit = 0.000001 USDF) as a decimal string, with the same amount in USDF (and in dollars, 1 USDF = $1 of compute).",
      "properties": {
        "units": {
          "type": "string",
          "description": "USDF base units.",
          "pattern": "^-?[0-9]+$"
        },
        "usdf": {
          "type": "string",
          "description": "The amount in USDF, to six decimals."
        },
        "usd": {
          "type": "string",
          "description": "The amount in dollars."
        }
      },
      "required": [
        "units"
      ]
    },
    "Efficiency": {
      "type": "object",
      "description": "Tokens per dollar and tokens per watt for one request (the routing docs, Tokens per dollar). Derived from what was served and charged; not part of the signed statement.",
      "properties": {
        "tokens_per_dollar": {
          "anyOf": [
            {
              "type": "number",
              "description": "The request's tokens (prompt plus completion) for each dollar it cost in all (the balance's part, free credit's and any markup); null when it cost nothing."
            },
            {
              "type": "null"
            }
          ]
        },
        "at_source_price": {
          "anyOf": [
            {
              "type": "number",
              "description": "The same tokens for each dollar of the same usage at the source price (source_cost where the request was charged at the public price, else list_cost); null where the source price is not known."
            },
            {
              "type": "null"
            }
          ]
        },
        "at_benchmark_price": {
          "anyOf": [
            {
              "type": "number",
              "description": "The same tokens for each dollar of the same usage at the per-token list price published for the model by the router Foundry's benchmarks compare against (prompt tokens at its prompt price, completion tokens at its completion price); null where it lists none."
            },
            {
              "type": "null"
            }
          ]
        },
        "tokens_per_watt": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "value": {
                  "type": "number",
                  "description": "Completion tokens generated for each watt-hour drawn generating them, on the route that served."
                },
                "unit": {
                  "type": "string",
                  "const": "tokens_per_wh"
                },
                "basis": {
                  "type": "string",
                  "description": "measured: the power a Foundry operator's machine reported drawing while it generated (its last 7 days); estimated: a public per-model figure (GPU energy only).",
                  "enum": [
                    "measured",
                    "estimated"
                  ]
                },
                "source": {
                  "anyOf": [
                    {
                      "type": "string",
                      "description": "For an estimate, the dataset it came from; null for a measured figure."
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "value",
                "unit",
                "basis",
                "source"
              ]
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "tokens_per_dollar",
        "at_source_price",
        "at_benchmark_price",
        "tokens_per_watt"
      ]
    }
  }
}