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

FieldTypeRequiredWhat it is
querystringYes—
documentsarrayYesArray of {id, text}
max_tokensintegerNo—

Output fields

How reliably each field appears in a successful answer.

FieldTypeAppears
excludedarrayAlways (present in every successful answer)
selectedarrayAlways (present in every successful answer)
tokens_remainingintegerAlways (present in every successful answer)
total_tokens_usedintegerAlways (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
  }'

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