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

# Report Mle Agent Turn Billing

`POST /v1/finetune-agent/sessions/{session_id}/billing/agent-turn`

## Request

- Base URL: `https://api.pioneer.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.pioneer.ai/v1/finetune-agent/sessions/{session_id}/billing/agent-turn`
- Auth: one of:
  - API key in header `X-API-Key`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/pioneer/apis/brain-api/docs/v1/finetune-agent/sessions/:session_id/billing/agent-turn/post.ts> (a function with typed inputs; its response is checked against the schema)

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, uuid, 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

## Changes

- **2026-09-24** `0e5e86e2bae5`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/pioneer/apis/brain-api/changes/v1/finetune-agent/sessions/:session_id/billing/agent-turn/post.md)

---

[API](https://skmtc.dev/pioneer/apis/brain-api.md) - [All operations](https://skmtc.dev/pioneer/apis/brain-api/llms.txt) - [OpenAPI document](https://skmtc.dev/pioneer/apis/brain-api/revisions/0e5e86e2bae5?raw)
