Llm utils API
This page documents the 4 gateway endpoints tagged llm utils 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 |
|---|---|---|
| POST | /utils/token_counter | Count the tokens of a prompt |
| GET | /utils/supported_openai_params | List the OpenAI parameters a model accepts |
| GET | /utils/model_info | Look up a model in the built-in price and limits list |
| POST | /utils/transform_request | Show the provider request the gateway would send |
Endpoints
POST /utils/token_counter
Count the tokens of a prompt
Count how many tokens a prompt or a list of messages uses for a model, without sending it to the model.
The count comes from the gateway's local tokenizer for that model. Set the call_endpoint query parameter to
true to ask the provider's own token counting API instead, where the provider has one (for example Anthropic
or Google AI Studio). If that call fails, the gateway falls back to the local count.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
call_endpoint | query | boolean | No |
Request body (application/json, schema TokenCountRequest):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
prompt | string or null | No | Prompt |
messages | array of object or null | No | Messages |
contents | array of object or null | No | Contents |
tools | array of object or null | No | Tools |
system | any or null | No | System |
Example request:
curl -X POST "http://localhost:4000/utils/token_counter" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [
{
"role": "user",
"content": "How many tokens is this message?"
}
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json TokenCountResponse |
| 400 | Neither prompt, messages nor contents was sent | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 503 | Token counting is disabled and no provider API result available | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
total_tokens | integer | Yes | How many tokens the prompt or messages use. |
request_model | string | Yes | The model name the request sent. |
model_used | string | Yes | The provider model the count was made for. |
tokenizer_type | string | Yes | Which tokenizer counted, for example openai_tokenizer. |
original_response | object or null | No | The provider's own answer, when its token counting API was called. |
error | boolean | No | True when the provider's token counting call failed. |
error_message | string or null | No | Why the provider's token counting call failed. |
status_code | integer or null | No | The HTTP status the provider's token counting API returned. |
GET /utils/supported_openai_params
List the OpenAI parameters a model accepts
Tell a client which OpenAI request parameters, such as tools or response_format, the gateway can translate for a model, so it only sends ones that work. model is a model group on this gateway or any provider model name. Any valid key can call it, and nothing changes.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/utils/supported_openai_params?model=claude-sonnet-5-5" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The parameter names the model accepts. | application/json _SupportedOpenAIParamsResponse |
| 400 | The model name maps to no known provider | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
supported_openai_params | array of string or null | Yes | Supported Openai Params |
GET /utils/model_info
Look up a model in the built-in price and limits list
Show the built-in entry for any provider model, whether or not it is set up on this gateway: its context window, output limit, price per token and supported features. Use it to check what a model would cost before adding it. model_info holds every field of the entry plus key and supported_openai_params. Any valid key can call it, and nothing changes.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model | query | string | Yes | |
custom_llm_provider | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/utils/model_info?model=claude-sonnet-5-5" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The model's entry in the built-in list. | application/json _ModelInfoLookupResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 404 | The model is not in the built-in list | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model |
custom_llm_provider | string | Yes | Custom Llm Provider |
model_info | object | Yes | Model Info |
POST /utils/transform_request
Show the provider request the gateway would send
Build the provider request for a chat completion body without sending it. call_type is completion and request_body is the body you would send to /v1/chat/completions. The answer carries the provider URL, headers and body, with credentials removed, so you can see how the gateway translates a request. A body that names client side credentials or endpoints the admin has not allowed is rejected with 400.
Request body (application/json, schema TransformRequestBody):
| Field | Type | Required | Description |
|---|---|---|---|
call_type | "completion" | Yes | Always completion: the preview only supports a chat completions body |
request_body | object | Yes | Request Body |
Example request:
curl -X POST "http://localhost:4000/utils/transform_request" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"call_type": "completion",
"request_body": {
"model": "claude-sonnet-5-5",
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The translated provider request. When the gateway cannot build it, for example for an unknown model, the answer is still 200 and carries only error | application/json RawRequestTypedDict |
| 400 | Rejected Request: api_base is not allowed in request body. Clientside passthrough requires explicit admin opt-in via either general_settings.allow_client_side_credentials = true (proxy-wide) or configurable_clientside_auth_params on the deployment in your proxy config.yaml. or Rejected Request: model_list is not allowed in the request body. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
raw_request_api_base | string or null | No | Raw Request Api Base |
raw_request_body | object or null | No | Raw Request Body |
raw_request_headers | object or null | No | Raw Request Headers |
error | string or null | No | Error |