Context Window Optimiser
Rank document chunks by relevance and choose the ones that fit your token budget, with a score for each.
Pay by wallet (x402) AI-generated
context-window-optimize Example
Input
{
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"documents": [
"test_item"
]
} Answer
{
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"excluded": [
{
"reason": "low relevance"
}
],
"selected": [],
"max_tokens": 4000,
"selected_count": 0,
"total_documents": 1,
"tokens_remaining": 4000,
"total_tokens_used": 0
} Inputs
| Field | Type | Required | What it is |
|---|---|---|---|
query | string | Yes | — |
documents | array | Yes | Array of {id, text} |
max_tokens | integer | No | — |
Output fields
How reliably each field appears in a successful answer.
| Field | Type | Appears |
|---|---|---|
excluded | array | Always (present in every successful answer) |
selected | array | Always (present in every successful answer) |
tokens_remaining | integer | Always (present in every successful answer) |
total_tokens_used | integer | Always (present in every successful answer) |
How to call it
The same tool through each route. MCP clients reach it through Strale’s server at https://api.strale.io/mcp; the call below is what the agent sends.
# Needs an API key. max_price_cents caps what this call may cost.
curl -X POST https://api.strale.io/v1/do \
-H "Authorization: Bearer $STRALE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"capability_slug": "context-window-optimize",
"inputs": {
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"documents": [
"test_item"
]
},
"max_price_cents": 3
}' {
"tool": "strale_execute",
"arguments": {
"slug": "context-window-optimize",
"inputs": {
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"documents": [
"test_item"
]
},
"max_price_cents": 3
}
} import { Strale } from "straleio";
const strale = new Strale({ apiKey: process.env.STRALE_API_KEY! });
const result = await strale.do({
capability_slug: "context-window-optimize",
inputs: {
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"documents": [
"test_item"
]
},
max_price_cents: 3,
}); import os
from straleio import Strale, DoRequest
strale = Strale(api_key=os.environ["STRALE_API_KEY"])
result = strale.do(DoRequest(
capability_slug="context-window-optimize",
inputs={
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"documents": [
"test_item",
],
},
max_price_cents=3,
)) # No account. The first request answers 402 with the price in USDC;
# an x402 client pays it from your wallet and repeats the request.
curl -i -X POST https://api.strale.io/x402/v2/context-window-optimize \
-H 'Content-Type: application/json' \
-d '{
"query": "SELECT * FROM users WHERE active = true LIMIT 10",
"documents": [
"test_item"
]
}' Limitations
Token savings depend on the target model
Optimisation suggestions use general practices; actual token savings depend on the target model’s tokenizer.
What to do instead: Measure actual token counts with the target model's tokenizer before and after applying suggestions
Related tools
- Agent Trace Analysis €0.20
- API Docs Generator €0.20
- API Mock Responses €0.05
- Changelog Generator €0.03
- Code Converter €0.05
- Commit Message Generator €0.05