cf-agent · API documentation

Cloudflare Worker hosting KurAgent, an AI assistant with tool calling. All endpoints accept JSON, return JSON or Server-Sent Events, and are rate-limited per IP.

Base URLhttps://agent.krsz.in

Stack

Runtime
Cloudflare Workers · @opennextjs/cloudflare · Next.js 15
Model pool
gemma-4-31b-it → gemma-4-26b-a4b-it (TPD fallback)
Session store
KV (1h TTL, last 20 turns trimmed per turn)
Tool timeout
TOOL_TIMEOUT_MS env var, default 5 000 ms
Max tool calls
5 iterations per chat request

Endpoints

POST/api/chat2 / 10s burst · 100 / day per IP
Streamed chat with tool-calling loop
Request
{
  "session_id": "user-abc-123",
  "message": "What time is it in Tokyo?",
  "options": {
    "temperature": 0.9,
    "maxTokens": 8192
  }
}
Response
Content-Type: text/event-stream

data: {"type":"start_process","content":""}
data: {"type":"start_think","content":"User wants Tokyo time."}
data: {"type":"think","content":"Calling get_time tool."}
data: {"type":"end_think","content":""}
data: {"type":"tool_start","tool":"get_time","args":{"timezone":"Asia/Tokyo"},"iteration":1}
data: {"type":"tool_result","tool":"get_time","result":{"time":"2026-07-21 22:14 JST"},"success":true}
data: {"type":"end_tool","content":"tool executed successfully"}
data: {"type":"start_text","content":"It's "}
data: {"type":"text","content":"22:14 JST in Tokyo."}
data: {"type":"end_text","content":""}
data: {"type":"end_process","content":"done, hitIterationLimit: false, toolCalls: 1"}
GET/api/toolNo rate limit (read-only)
List all registered tools
Request
curl https://agent.krsz.in/api/tool
Response
{
  "tools": [
    {
      "name": "get_time",
      "description": "Get current time in a timezone",
      "example": "{\"timezone\": \"Asia/Tokyo\"}"
    }
  ],
  "functionDeclarations": [
    {
      "name": "get_time",
      "description": "Get current time in a timezone",
      "parameters": { /* JSON Schema */ }
    }
  ]
}
POST/api/tool10 / 10s burst · 200 / day per IP
Execute a tool directly (no LLM)
Request
{
  "name": "get_time",
  "args": { "timezone": "Asia/Tokyo" }
}
Response
{
  "success": true,
  "tool": "get_time",
  "result": {
    "time": "2026-07-21 22:14:11 JST",
    "timezone": "Asia/Tokyo",
    "utc": "2026-07-21T13:14:11.000Z"
  }
}

SSE event order (/api/chat)

Events are JSON-encoded on lines starting with data:. The stream always ends with end_process or error.

EventWhenDescription
start_processFirstStream opened, processing started.
start_think / think / end_thinkOptionalModel's internal reasoning (filtered from final text).
tool_startOptionalModel decided to call a tool. Carries tool name + args.
tool_resultAfter tool_startTool execution finished. result + success.
end_toolAfter tool_resultTool block closed.
start_text / text / end_textFinalUser-visible response (think blocks excluded).
end_processLastStream complete. Reports hitIterationLimit and toolCalls count.
errorOn failureModel or tool error. Stream still closes cleanly.

Available tools

Loaded live from GET /api/tool. Tools run with a 5 s default timeout and may invoke external services (Brave Search, etc.).

Loading tools…