Skip to main content

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.

MethodPathSummary
POST/utils/token_counterCount the tokens of a prompt
GET/utils/supported_openai_paramsList the OpenAI parameters a model accepts
GET/utils/model_infoLook up a model in the built-in price and limits list
POST/utils/transform_requestShow 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:

NameInTypeRequiredDescription
call_endpointquerybooleanNo

Request body (application/json, schema TokenCountRequest):

FieldTypeRequiredDescription
modelstringYesModel
promptstring or nullNoPrompt
messagesarray of object or nullNoMessages
contentsarray of object or nullNoContents
toolsarray of object or nullNoTools
systemany or nullNoSystem

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:

StatusDescriptionBody
200Successful Responseapplication/json TokenCountResponse
400Neither prompt, messages nor contents was sentapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
503Token counting is disabled and no provider API result availableapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
total_tokensintegerYesHow many tokens the prompt or messages use.
request_modelstringYesThe model name the request sent.
model_usedstringYesThe provider model the count was made for.
tokenizer_typestringYesWhich tokenizer counted, for example openai_tokenizer.
original_responseobject or nullNoThe provider's own answer, when its token counting API was called.
errorbooleanNoTrue when the provider's token counting call failed.
error_messagestring or nullNoWhy the provider's token counting call failed.
status_codeinteger or nullNoThe 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:

NameInTypeRequiredDescription
modelquerystringYes

Example request:

curl -X GET "http://localhost:4000/utils/supported_openai_params?model=claude-sonnet-5-5" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The parameter names the model accepts.application/json _SupportedOpenAIParamsResponse
400The model name maps to no known providerapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
supported_openai_paramsarray of string or nullYesSupported 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:

NameInTypeRequiredDescription
modelquerystringYes
custom_llm_providerquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/utils/model_info?model=claude-sonnet-5-5" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The model's entry in the built-in list.application/json _ModelInfoLookupResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
404The model is not in the built-in listapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
modelstringYesModel
custom_llm_providerstringYesCustom Llm Provider
model_infoobjectYesModel 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):

FieldTypeRequiredDescription
call_type"completion"YesAlways completion: the preview only supports a chat completions body
request_bodyobjectYesRequest 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:

StatusDescriptionBody
200The translated provider request. When the gateway cannot build it, for example for an unknown model, the answer is still 200 and carries only errorapplication/json RawRequestTypedDict
400Rejected 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
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
raw_request_api_basestring or nullNoRaw Request Api Base
raw_request_bodyobject or nullNoRaw Request Body
raw_request_headersobject or nullNoRaw Request Headers
errorstring or nullNoError