Skip to content

Conversation

@sujalmh
Copy link

@sujalmh sujalmh commented Dec 16, 2025

The Responses API returns messages with function_call content blocks which cause get_num_tokens_from_messages to raise a ValueError: Unrecognized content block type. This occurs because the token counter internally uses the chat/completions format logic, which does not recognize these blocks.

This PR updates _format_message_content to filter out function_call blocks when formatting messages for the chat/completions API (which includes the token counter). These blocks are redundant for token counting as the actual tool calls are already handled via the separate tool_calls field, ensuring accurate counts without errors.

Fixes #34378

Breaking Changes: None.

@github-actions github-actions bot added integration PR made that is related to a provider partner package integration openai `langchain-openai` package issues & PRs fix For PRs that implement a fix labels Dec 16, 2025
@sujalmh sujalmh marked this pull request as ready for review December 16, 2025 19:56
@sujalmh sujalmh requested review from ccurme and mdrxy as code owners December 16, 2025 19:56
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 16, 2025

CodSpeed Performance Report

Merging #34396 will not alter performance

Comparing sujalmh:fix/token-counter-function-call (c21a249) with master (71778cb)

Summary

✅ 6 untouched
⏩ 28 skipped1

Footnotes

  1. 28 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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

Labels

fix For PRs that implement a fix integration PR made that is related to a provider partner package integration openai `langchain-openai` package issues & PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI token counter throws error if responses api content includes function_call

2 participants