Estimate baseline token usage
A read-only preview of what a candidate draft would cost in model context, so automation can trim before attempting a save.
The body is the same merge patch as PATCH /agents/{id}/draft: omitted fields come from the persisted draft, {} estimates it unchanged, and all normal authoring and reference validation runs.
This never writes the draft, baseline_tokens, the aggregate revision, or the audit log.
Reading the result
Compare baseline_tokens with max_model_len, the usable budget — 80% of model_context_limit. Exceeding the budget is reported in the successful estimate rather than as an error, so you can reduce prompt or tool cost first.
Using it as a preflight
The 200 ETag is the strong tag of the aggregate snapshot used to assemble the candidate. Pass it as If-Match on the subsequent draft PATCH, and any change made after the preflight fails with 412.
bearerAuthAuthorizationBearer <token>Use a Voice API key or connected-app OAuth access token. Authentication.
id*stringuuidIdempotency-Key?stringOptional. When supplied, identical retries replay the saved result. Retries and idempotency.
^[A-Za-z0-9!#$%&'*+.^_`|~-]+$1 <= length <= 255application/json- body
Read-only candidate patch with exactly the same closed authoring shape and merge semantics as PATCH /agents/{id}/draft. Omitted fields are loaded from the current persisted draft; therefore {} estimates that draft unchanged. When the agent has no draft, the request must supply prompt so a complete in-memory candidate can be assembled. The server performs the same template, catalog-reference, provider, transfer, topology, and baseline checks as a draft save but performs no write and emits no audit event.
prompt?stringNon-blank prompt template. Omit it to preserve current content; null is invalid and an empty string cannot erase runnable content.
1 <= length <= 500000pipeline_topology?stringLegacy engine selector; prefer pipeline_mode, which overrides it when both are sent. three_stage is accepted only when the deployment capability enables it, except that three_stage sent for a draft whose pipeline_mode is cascaded is the reported label being echoed back and is ignored. Most realtime STT integrations require two_stage_speechlm; the server validates the selected model's published capabilities.
"three_stage""two_stage_speechlm"pipeline_mode?stringSource-of-truth runtime pipeline selector. speech_model feeds the brain raw caller audio; cascaded feeds a realtime STT transcript to a text brain then TTS. Both modes run on the v2 turn engine, so the stored engine selector stays two_stage_speechlm; reads report pipeline_topology three_stage for cascaded and two_stage_speechlm for speech_model. Omit to preserve the current value.
"speech_model""cascaded"endpointing_mode?stringLegacy version-level turn endpointing selector; prefer behavior.turn_taking.endpointing_mode. auto uses the engine's default endpointing; stt uses STT-driven turn endpointing, which takes effect only on a cascaded pipeline with a transcriber whose stt_capabilities.endpointing in GET /providers reports capable and reliable; otherwise it falls back to auto at runtime rather than being rejected. Ignored when the same request supplies behavior: the value is then derived from behavior.turn_taking.endpointing_mode (absent means auto). Omit to preserve the current value. audio always uses the agent's own audio endpointer; auto lets Kejue pick (on the self-hosted speech recognizer that is the recognizer's own turn detection).
"auto""stt""audio"stt_language?string^[A-Za-z0-9_-]*$length <= 64stt_language_hints?array<string>Languages the caller is expected to speak, for transcribers whose auto-detection takes a hint list (providers with stt_capabilities.language_hints: true in GET /providers). Each entry is a 2–3 letter language code with an optional two-letter region, such as ar, en, or pt-br; the server trims, lower-cases, and de-duplicates the list and drops blank entries, and at most 10 distinct codes may remain (code too_many). Every code must be in the selected provider's stt_capabilities.languages catalog. Send an empty array to clear; omit to preserve. Setting a non-empty list on a transcriber without the capability is rejected with code incompatible_model; a stored list survives an STT switch and is simply not forwarded.
stt_vocabulary?|Per-agent recognition vocabulary: custom terms, free-text context notes, key/value hints, and spoken-to-written translations the recognizer should favor. Accepted when the selected transcriber advertises stt_capabilities.vocabulary: true in GET /providers (already resolved for the selected model). Send null or an empty object to clear; omit to preserve. Rejected with code incompatible_model otherwise.
behavior?Complete version-scoped behavior document. Supplying behavior replaces the previous behavior document on the mutable draft; omitted behavior leaves it unchanged. Omitted blocks and fields use the runtime defaults documented on their schemas. New writes use only this canonical shape; supported legacy inactivity and transfer rows are normalized before public responses are emitted.
llm_provider_model_id?|UUID of an enabled compatible catalog resource, or an empty string to clear the optional reference.
stt_provider_model_id?|UUID of an enabled compatible catalog resource, or an empty string to clear the optional reference.
tts_provider_model_id?|UUID of an enabled compatible catalog resource, or an empty string to clear the optional reference.
tts_voice_id?|UUID of an enabled compatible catalog resource, or an empty string to clear the optional reference.
speechlm_provider_model_id?|UUID of an enabled compatible catalog resource, or an empty string to clear the optional reference.
tts_voice_settings?Writable provider-specific override layered over the selected voice's catalog settings. The selected connector permits only its advertised subset and can impose narrower ranges; inspect voice_settings_schema in GET /providers before authoring. Send {} to clear every per-agent override. Dialect is intentionally absent because it belongs to the selected voice catalog entry.
Token estimate and configured headroom.
application/json- response
baseline_tokens*integer0 <= valuemax_model_len*integerUsable token budget for the system prompt plus tools — 80% of model_context_limit, the rest is reserved for the conversation. A draft save is rejected when baseline_tokens exceeds it. This is the number the dashboard shows.
0 <= valuemodel_context_limit*integerRaw deployment model context length the budget derives from.
1 <= valueheadroom_budget*integerDeprecatedCompatibility alias; always equals max_model_len.
0 <= valuecomponents*curl -X POST 'https://api.kejue.co/v1/agents/497f6eca-6276-4993-bfeb-53cbbbba6f08/estimate-baseline' \ -H 'Content-Type: application/json' \ -d '{}'{ "baseline_tokens": 4821, "max_model_len": 24576, "model_context_limit": 32768, "headroom_budget": 24576, "components": { "system": 1210, "tools": 3611 }}