Optimize context
Send a question and the context you would give your model. Get back the context worth sending, and a report on every decision.
Endpoint#
Authenticated with a bearer key (Authentication). The request and response are JSON.
Request body#
querystringrequiredThe question your model will answer, usually the user's message. Candidates are scored against it. Up to 8,000 characters.
candidatesarrayrequiredThe context items to choose from, up to 500. See Candidates.
agentstringoptionalDefault: defaultA stable name for the call site, such as support-assistant. Groups requests in the dashboard, selects the agent's budget, and scopes the quality check's tuning.
modelstringoptionalThe model id you send this context to, like gpt-6.1-sol or claude-sonnet-5-5. Costs in the report are priced for it. Unknown models fall back to your project's default model; report.model shows which was used.
conversationstringoptionalTurns on cache-safe mode: items seen earlier in this conversation keep their first decision. 1 to 128 characters: letters, digits, _ - . :. See Conversations and prompt caching.
Candidates#
Each candidate is either an object or a plain string:
textstringrequiredThe content, up to 60,000 characters. HTML, JSON, logs and test output are cleaned automatically.
idstringoptionalDefault: c0, c1, …Your identifier, returned in context and report.items. Use your document or chunk id. Up to 80 characters.
sourcestringoptionalDefault: contextA label for where it came from. Any name you choose works, such as rag, web, history or your own intern_data. Used to break savings down by source and to filter requests in the dashboard. It doesn't change scoring.
Stored lowercase, up to 40 characters. Characters other than letters, digits, _, - and spaces become -, so Intern.Data is stored as intern-data.
Tuning#
budgetintegeroptionalDefault: agent budget, then project defaultThe most tokens of context that can come back, from 200 to 200,000 (values outside are clamped). Strongest items are kept first. Defaults to the agent's budget set in the dashboard, otherwise the project default (6,000).
aggressivenessstringoptionalDefault: project setting (balanced)conservative, balanced or aggressive: the base relevance threshold (0.9, 1.4, 1.9 on the 0 to 3 scale). See Selection.
Model routing#
Optional. Sending models turns on routing advice in report.route. See Model routing.
modelsstring[]optional2 to 10 model ids you approve, from any providers. Each must be in the catalog or priced in Settings → Models, otherwise the request returns 422.
systemstringoptionalYour model's instructions. Helps judge how demanding the task is.
outputTokensintegeroptionalDefault: 500Your typical answer length, to price output in the switch estimate.
promptTokensintegeroptionalYour full prompt size including history, for example the last usage.input_tokens. Defaults to what Contextwaise sees.
Response#
idstringrequiredThe request id, as shown in the dashboard (req_…).
contextarrayrequiredThe kept candidates as { id, text, source }, in the order you sent them. Send these to your model and store them in the conversation. text is the cleaned version.
reportobjectrequiredEvery figure and decision behind the result, described below.
The report#
tokensobjectrequiredbefore, after, saved and savedPct: input tokens of the context as received and as returned.
costobjectrequiredbefore and after at the model's input price, scorer (the cost of relevance scoring) and avoided (what you save, net of scoring). In USD.
modelstring | nullrequiredThe model costs were priced for. null when your project's custom price was used.
inputPricePerMillionnumberrequiredThe input price used, in USD per 1M tokens.
itemsarrayrequiredOne entry per candidate. See Items.
budget · aggressiveness · thresholdnumber · string · numberrequiredThe settings applied. threshold includes the agent's learned adjustment.
conversationobject | nullrequiredWith a conversation id: { id, reused, protected }, the number of decisions reused, and whether they were safely stored.
routeobject | nullrequiredRouting advice when models was sent. See Read the advice.
guardnullrequiredThe quality check runs after the response, so it is null here. Its verdict appears on the request in the dashboard.
latencyMs · timingsnumber · objectrequiredTotal time in milliseconds from the request arriving, and the split by step: auth, project, score, select.
Items#
id · sourcestringrequiredThe candidate's id and source.
keptbooleanrequiredWhether it is in context.
reasonstringrequiredrelevant (kept), low_relevance (below the threshold), duplicate (repeats a kept item, see duplicateOf) or over_budget (relevant, but the budget was full).
scorenumberrequiredRelevance from 0 (unrelated) to 3 (essential).
tokens · originalTokensintegerrequiredThe size after cleanup, and as received. They differ when cleanup removed noise.
cleanedstring[]optionalWhat cleanup removed, such as converted HTML to text or dropped 12 empty JSON fields. Present only when the item was cleaned.
duplicateOfstringoptionalFor duplicates: the id of the kept item it repeats.
reusedbooleanoptionalIn cache-safe mode: the decision was made earlier in the conversation.