Skip to content

Bound chat turns in time, log their usage, and name spend limits - #185

Draft
duaneatat wants to merge 1 commit into
mainfrom
db/chat-turn-limits
Draft

duaneatat wants to merge 1 commit into
mainfrom
db/chat-turn-limits

Conversation

@duaneatat

Copy link
Copy Markdown
Collaborator

Three small server-side protections to have in place before more testers use chat.

  • A turn ends with a readable error after CHAT_TURN_TIMEOUT seconds (default 180); before, a stalled provider held the stream until nginx gave up
  • One chat_turn log line per turn: outcome, model, seconds, requests, tool calls, tokens, cost. Never the question or answer. podman logs api | grep chat_turn gives real usage until there is a ledger
  • OpenRouter's 403 key-limit and OpenAI's 429 spend-limit errors now show the usage-limit message (the known gap in data-chat.md)
  • Checked against the running demo API: the log line appears under uvicorn

A stalled provider could hold a stream open until the proxy gave up,
so a turn now ends with a readable error after CHAT_TURN_TIMEOUT
seconds (180 by default). Each turn writes one chat_turn log line with
its outcome, tokens, and cost, never the question or answer. Provider
spend limits that arrive as 403 or 429 instead of 402 now read as the
usage limit being reached.
@duaneatat
duaneatat marked this pull request as draft November 12, 2026 22:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant