Cost Optimization API
This page documents the 1 gateway endpoint tagged Cost Optimization in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| GET | /cost_optimization/prompt_caching/requests | List requests with their prompt caching result |
Endpoints
GET /cost_optimization/prompt_caching/requests
List requests with their prompt caching result
Return recent requests between start_date and end_date with the cache tokens they read and wrote, whether the gateway inserted the cache breakpoint itself, what they cost and what caching saved on each, newest first. filter is all, injected (the gateway added the breakpoint) or hits (the request read from the cache). Pages continue with cursor_start_time and cursor_request_id copied from next_cursor. Proxy admins and admin viewers only. The Prompt Caching tab of the Cost Optimization page shows this table.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start_date | query | string | Yes | Start of the range, ISO 8601, UTC when no zone |
end_date | query | string | Yes | End of the range, ISO 8601, UTC when no zone |
page_size | query | integer | No | Requests per page, 1 to 100 |
filter | query | enum: "all", "injected", "hits" | No | all, injected (the gateway added the cache breakpoint) or hits (read from the cache) |
cursor_start_time | query | string or null | No | start_time from next_cursor of the previous page |
cursor_request_id | query | string or null | No | request_id from next_cursor of the previous page |
Example request:
curl -X GET "http://localhost:4000/cost_optimization/prompt_caching/requests?start_date=string&end_date=string" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | One page of requests, newest first, with the cursor for the next page. | application/json PromptCachingRequestsResponse |
| 400 | end_date must not be earlier than start_date or cursor_start_time and cursor_request_id must be provided together | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Only proxy admin roles can view prompt caching requests | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
requests | array of PromptCachingRequest | Yes | Requests |
page_size | integer | Yes | Page Size |
has_more | boolean | Yes | Has More |
next_cursor | PromptCachingRequestCursor or null | Yes |