---
title: "Report Mle Agent Turn Billing"
method: POST
path: "/mle-agent/sessions/{session_id}/billing/agent-turn"
tags: ["agent-chat-sessions"]
---

# Report Mle Agent Turn Billing

`POST /mle-agent/sessions/{session_id}/billing/agent-turn`

Crash-safe per-turn billing endpoint for MLE chat sessions.

Args:
    request: FastAPI request used by the rate-limiter.
    session_id: ``agent_chat_sessions.id`` for the active chat.
    body: Per-turn usage payload with dedup key.
    auth: Authenticated caller; must own ``session_id``.

Returns:
    AgentTurnBillingResponse with ``request_id`` and ``billed`` flag.

Raises:
    HTTPException: 404/403 for ownership failures.

## Path parameters

- `session_id` string, required

## Request body

- AgentTurnBillingRequest — Legacy per-turn LLM token usage compatibility report from a sandbox. Older sandbox images may still POST one of these requests per LLM turn. Brain now bills brokered sandbox calls from server-observed ``/v1/messages`` usage, so the sandbox-supplied provider/model/token fields are accepted for compatibility and rollout metrics but are not trusted for billing. The ``turn_id`` is generated client-side (typically the LangChain callback's ``run_id`` UUID) and is the dedup key. Replays of the same workload/turn pair return the cached compatibility result.
  - `turn_id` string, required — Sandbox-supplied dedup key for this turn (UUID recommended).
  - `provider` string, required
  - `model` string, required
  - `input_tokens` integer
  - `output_tokens` integer

## Response `200`

Successful Response

- AgentTurnBillingResponse — Response from the legacy per-turn self-report endpoint. ``billed`` is ``False`` for accepted compatibility self-reports because Brain's brokered ``/v1/messages`` path is the billing source of truth. ``request_id`` is normally ``None`` for newly accepted reports, but may contain a cached legacy id for old dedup entries.
  - `request_id` string, nullable — Normally null for accepted compatibility self-reports; may contain a cached legacy requests row id for old dedup entries.
  - `billed` boolean, required — False for accepted compatibility self-reports; brokered sandbox LLM usage is billed server-side on /v1/messages.

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/pioneer/apis/brain-api.md) · [All operations](https://skmtc.net/pioneer/apis/brain-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/pioneer/brain-api/versions/31dfe831e079/schema)
