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/jsonRequest Payload
| JSON Key | Type | Required | Description |
|---|---|---|---|
text | string | Yes | The natural language prompt to optimize. |
task | string | No | Optional guidance for preservation ranking. |
budget | number|string | No | Absolute tokens (e.g. 500) or percentage (e.g. "20%"). |
model | string | No | Target 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 Key | Type | Description |
|---|---|---|
optimized_text | string | The resulting optimized prompt. |
original_tokens | number | Input token count. |
optimized_tokens | number | Output token count. |
reduction_percent | number | Percentage of tokens saved. |
latency_ms | number | Processing time in milliseconds. |
soft_limit_enforced | boolean | true 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