Skip to content

fix(agent-server): report OpenAI gateway token usage#3546

Merged
enyst merged 1 commit into
OpenHands:openhands/openai-chat-completions-gatewayfrom
smolpaws:smolpaws/openai-gateway-token-usage
Jun 6, 2026
Merged

fix(agent-server): report OpenAI gateway token usage#3546
enyst merged 1 commit into
OpenHands:openhands/openai-chat-completions-gatewayfrom
smolpaws:smolpaws/openai-gateway-token-usage

Conversation

@smolpaws

@smolpaws smolpaws commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

This PR was created by an AI agent (OpenHands) on behalf of the user.

Summary

  • Populates the OpenAI chat completion usage field from state.stats.get_combined_metrics().accumulated_token_usage.
  • Adds deterministic token metrics to the live gateway test and asserts prompt_tokens, completion_tokens, and total_tokens.

Validation

  • TMUX_TMPDIR=/tmp/oh-test-tmux-precommit-$RANDOM uv run pre-commit run --files openhands-agent-server/openhands/agent_server/openai_service.py tests/cross/test_remote_conversation_live_server.py
  • TMUX_TMPDIR=/tmp/oh-test-tmux-$RANDOM uv run pytest tests/cross/test_remote_conversation_live_server.py::test_openai_chat_completions_gateway_over_real_server -q
  • TMUX_TMPDIR=/tmp/oh-test-tmux-$RANDOM uv run pytest tests/agent_server/test_api_authentication.py::test_openai_routes_accept_bearer_session_key -q
  • TMUX_TMPDIR=/tmp/oh-test-tmux-$RANDOM uv run pytest tests/cross/test_remote_conversation_live_server.py::test_remote_conversation_over_real_server tests/cross/test_remote_conversation_live_server.py::test_openai_chat_completions_gateway_over_real_server tests/cross/test_remote_conversation_live_server.py::test_subagent_definitions_forwarded_to_server -q

Intended to be merged into PR #3545's branch.

@smolpaws can click here to continue refining the PR

Co-authored-by: openhands <openhands@all-hands.dev>
@enyst enyst marked this pull request as ready for review June 6, 2026 12:40
@enyst enyst merged commit ea64fcf into OpenHands:openhands/openai-chat-completions-gateway Jun 6, 2026
15 of 16 checks passed
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.

3 participants