Skip to main content

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.

MethodPathSummary
GET/cost_optimization/prompt_caching/requestsList 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:

NameInTypeRequiredDescription
start_datequerystringYesStart of the range, ISO 8601, UTC when no zone
end_datequerystringYesEnd of the range, ISO 8601, UTC when no zone
page_sizequeryintegerNoRequests per page, 1 to 100
filterqueryenum: "all", "injected", "hits"Noall, injected (the gateway added the cache breakpoint) or hits (read from the cache)
cursor_start_timequerystring or nullNostart_time from next_cursor of the previous page
cursor_request_idquerystring or nullNorequest_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:

StatusDescriptionBody
200One page of requests, newest first, with the cursor for the next page.application/json PromptCachingRequestsResponse
400end_date must not be earlier than start_date or cursor_start_time and cursor_request_id must be provided togetherapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admin roles can view prompt caching requestsapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
requestsarray of PromptCachingRequestYesRequests
page_sizeintegerYesPage Size
has_morebooleanYesHas More
next_cursorPromptCachingRequestCursor or nullYes