Agents
The routes a model's agent calls to take work and answer it, and the one that says whether an agent is connected.
A model registered with inference: {"type": "agent"} is run in its owner's environment by an agent that connects out to the API and asks for work. Requests for the model become jobs; the agent takes them and answers. Run a model with an agent covers what that means for a model. The Python client's agent, kaimei.agent.serve, calls these routes; they are here for writing an agent of your own. Every route but the status needs a key that may write models (models:write).
While a request waits for an agent's answer it holds no database connection. Each API process lets 16 requests wait for agents at once, 6 of them for one organization's models; past either, the request is 429 agent_busy with Retry-After and details: {limit, scope} (scope is organization or server). A background analysis waits for a place instead, up to five minutes.
| Job kind | payload | result |
|---|---|---|
predict | {"rows": [...]} | {"predictions": [[...], ...]}, one list of numbers for each row; raw: true when they are the model's own output, and link (softmax, sigmoid or none) for how to read them when the model has no structure to say (raw outputs) |
trace | {"input", "nodes"} | {"frames": [...], "prediction": [...]}, frames by node_id with value or summary |
activations | {"input", "nodes", "channels", "channel_start", "max_side", "units"} | {"stages": [...], "prediction": [...], "forward_ms"}, stages in the API's own form |
tokenize | {"feature", "text", "max_length"} | {"ids": [...]}, special tokens included |
#Agent status
/v1/models/{model}/agentAPI key or sessionWhether an agent is connected for the model right now, and what it answers. An agent is connected while it has asked for work in the last 45 seconds, or is busy with a job.
Path parameters
Model id or slug.
Returns
{object: "model.agent", model_id, connected, capabilities, sessions}; each session {id, label, capabilities, info, created_at, last_seen_at}.status = client.models.agent_status("churn-in-our-vpc")
print(status.connected, status.capabilities)curl https://api.kaimei.ai/v1/models/churn-in-our-vpc/agent \
-H "Authorization: Bearer $KAIMEI_API_KEY"{
"object": "model.agent",
"model_id": "mdl_fe3d094de8e20e090aea",
"connected": true,
"capabilities": ["predict"],
"sessions": [
{
"id": "agt_bc9f6510c1a9da7d6b0e",
"label": "laptop",
"capabilities": ["predict"],
"info": {"framework": "sklearn", "client": "0.12.0"},
"created_at": "2026-11-22T19:41:36.571816Z",
"last_seen_at": "2026-11-22T19:41:36.590933Z"
}
]
}#Register an agent
/v1/models/{model}/agent/sessionsAPI key or sessionAn agent announcing itself for a model. Several may be connected at once, up to 32 a model (429 too_many_agent_sessions; an agent that stopped without saying so counts until it has been silent for 45 seconds); a job goes to the first that asks for it and can do it. Registering is limited to 60 an hour on Free, more on paid plans. A session not heard from in an hour is removed.
Path parameters
Model id or slug.
Body parameters
What the agent is called on the model's page, up to 120 characters.
What it answers: predict, trace, activations, tokenize. Unknown ones are dropped, and none at all is 400 invalid_capabilities.
Anything worth showing about it, such as its framework, device or client version: up to 16 keys, kept as short strings.
Returns
201 with {object: "model.agent.session", id, model_id, capabilities, wait_seconds, live_seconds}: how long one request for work may be held open (25), and how long silence is taken for a lost agent (45).curl -X POST https://api.kaimei.ai/v1/models/churn-in-our-vpc/agent/sessions \
-H "Authorization: Bearer $KAIMEI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"label": "laptop", "capabilities": ["predict"], "info": {"framework": "sklearn"}}'{
"object": "model.agent.session",
"id": "agt_bc9f6510c1a9da7d6b0e",
"model_id": "mdl_fe3d094de8e20e090aea",
"capabilities": ["predict"],
"wait_seconds": 25.0,
"live_seconds": 45.0
}#Ask for work
/v1/models/{model}/agent/sessions/{session_id}/pollAPI key or sessionThe next job the agent can do, held open until one arrives or wait runs out. The wait holds no thread and no database connection on the server. Two agents asking at once never get the same job, a job queued more than 5 minutes ago is no longer handed out, and one older than 6 minutes is removed. A model may have 32 requests for work waiting (429 too_many_agent_polls). 404 agent_session_not_found for a session that was closed or is not this model's.
Path parameters
Model id or slug.
From registering.
Body parameters
Seconds to wait for a job, 0 to 25.
Returns
{object: "model.agent.work", job}: null, or {id, kind, payload}.curl -X POST https://api.kaimei.ai/v1/models/churn-in-our-vpc/agent/sessions/agt_bc9f6510c1a9da7d6b0e/poll \
-H "Authorization: Bearer $KAIMEI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"wait": 20}'{
"object": "model.agent.work",
"job": {
"id": "job_d5dd998a02d842625ff6",
"kind": "predict",
"payload": {
"rows": [
{"tenure": 3.0, "seats": 2.0}
]
}
}
}#Answer a job
/v1/models/{model}/agent/jobs/{job_id}/resultAPI key or sessionThe agent's answer. It is checked like any upload before it is used, and the request that made the job gets it. 400 invalid_agent_answer for ok with no result, or a whole number beyond a float's range; 400 agent_answer_too_large past 4,000,000 values or 60,000 frames or stages; 404 agent_job_not_found for a job that no longer exists, because its caller stopped waiting (an agent notes it and moves on); 409 agent_job_not_running for one that is not waiting for an answer. An answer that passes these and still cannot be read, such as a summary with a negative size, makes the waiting request 502 invalid_agent_answer.
Path parameters
Model id or slug.
From the job.
Body parameters
Whether the agent did the work.
The answer, as the job's kind needs it. Required when ok.
Why it could not, up to 2,000 characters. The caller gets 502 agent_failed with it.
Returns
{object: "model.agent.work", job: null}.curl -X POST https://api.kaimei.ai/v1/models/churn-in-our-vpc/agent/jobs/job_d5dd998a02d842625ff6/result \
-H "Authorization: Bearer $KAIMEI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"ok": true, "result": {"predictions": [[0.31, 0.69]]}}'{
"object": "model.agent.work",
"job": null
}#Close a session
/v1/models/{model}/agent/sessions/{session_id}API key or sessionAn agent saying it is going away: the session is deleted. An agent that stops without saying so is no longer connected once it has been silent for 45 seconds. While no agent is connected, requests for the model answer 502 agent_offline; one that does not answer in the model's inference.timeout_s (60 seconds unless set, at most 300) makes the request 502 agent_timeout.
Path parameters
Model id or slug.
The session.
Returns
object: "model.agent.session".curl -X DELETE https://api.kaimei.ai/v1/models/churn-in-our-vpc/agent/sessions/agt_bc9f6510c1a9da7d6b0e \
-H "Authorization: Bearer $KAIMEI_API_KEY"{
"id": "agt_bc9f6510c1a9da7d6b0e",
"object": "model.agent.session",
"deleted": true
}