Skip to Content

REST API Reference

For languages without a first-class SDK, or for bare-metal implementations, you can interface directly with the /optimize REST endpoint.

The endpoint expects standard application/json data and Bearer token authentication.

HTTP Request

POST /optimize HTTP/1.1 Host: api.trunkate.ai Authorization: Bearer tk_live_... Content-Type: application/json

Request Payload

JSON KeyTypeRequiredDescription
textstringYesThe natural language prompt to optimize.
taskstringNoOptional guidance for preservation ranking.
budgetnumber|stringNoAbsolute tokens (e.g. 500) or percentage (e.g. "20%").
modelstringNoTarget LLM (default: gpt-4o).

Response Body

{ "optimized_text": "The optimized prompt here...", "original_tokens": 120, "optimized_tokens": 45, "reduction_percent": 62, "latency_ms": 12.5, "soft_limit_enforced": false }
JSON KeyTypeDescription
optimized_textstringThe resulting optimized prompt.
original_tokensnumberInput token count.
optimized_tokensnumberOutput token count.
reduction_percentnumberPercentage of tokens saved.
latency_msnumberProcessing time in milliseconds.
soft_limit_enforcedbooleantrue if the requested budget was too small and a fallback was used.

Example using cURL

# OPTION A: Fixed Token Budget curl -X POST https://api.trunkate.ai/optimize \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{"text": "...", "budget": 500}' # OPTION B: Proactive Percentage Buffer curl -X POST https://api.trunkate.ai/optimize \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{"text": "...", "budget": "20%"}'
Last updated on