Skip to Content
Agents

Estimate baseline token usage

Permissionagents:updateRetriesIdempotency-Key optionalAuthentication
POST
/agents/{id}/estimate-baseline

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.

Authorization

bearerAuth
headerAuthorizationBearer <token>

Use a Voice API key or connected-app OAuth access token. Authentication.

Path Parameters

id*string
Formatuuid

Header Parameters

Idempotency-Key?string

Optional. When supplied, identical retries replay the saved result. Retries and idempotency.

Match^[A-Za-z0-9!#$%&'*+.^_`|~-]+$
Length1 <= length <= 255

Request Body

application/json
  1. 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?string

Non-blank prompt template. Omit it to preserve current content; null is invalid and an empty string cannot erase runnable content.

Length1 <= length <= 500000
pipeline_topology?string

Legacy 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.

Value in"three_stage""two_stage_speechlm"
pipeline_mode?string

Source-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.

Value in"speech_model""cascaded"
endpointing_mode?string

Legacy 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).

Value in"auto""stt""audio"
stt_language?string
Match^[A-Za-z0-9_-]*$
Lengthlength <= 64
stt_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.

Response Body

Token estimate and configured headroom.

application/json
  1. response
baseline_tokens*integer
Range0 <= value
max_model_len*integer

Usable 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.

Range0 <= value
model_context_limit*integer

Raw deployment model context length the budget derives from.

Range1 <= value
headroom_budget*integerDeprecated

Compatibility alias; always equals max_model_len.

Range0 <= value
components*
curl -X POST 'https://api.kejue.co/v1/agents/497f6eca-6276-4993-bfeb-53cbbbba6f08/estimate-baseline' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "baseline_tokens": 4821,  "max_model_len": 24576,  "model_context_limit": 32768,  "headroom_budget": 24576,  "components": {    "system": 1210,    "tools": 3611  }}