litellm - 💡(How to fix) Fix [Bug]: Anthropic messages failed to handle spend log when stream is true

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

uld be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent]\n For further information visit https://errors.pydantic.dev/2.13/v/model_type')> Traceback (most recent call last): File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1867, in _success_handler_helper_fn result = self._handle_anthropic_messages_response_logging(result=result) File "/app/litellm/litellm_core_utils/litellm_logging.py", line 3465, in _handle_anthropic_messages_response_logging pydantic_result = AnthropicResponse.model_validate(result) File "/app/.venv/lib/python3.13/site-packages/pydantic/main.py", line 732, in model_validate return cls.pydantic_validator.validate_python( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ obj, ^^^^ ...<5 lines>... by_name=by_name, ^^^^^^^^^^^^^^^^ ) ^ pydantic_core._pydantic_core.ValidationError: 1 validation error for AnthropicResponse Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent] For further information visit https://errors.pydantic.dev/2.13/v/model_type

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/app/litellm/litellm_core_utils/litellm_logging.py", line 2549, in async_success_handler start_time, end_time, result = self._success_handler_helper_fn( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ start_time=start_time, ^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... standard_logging_object=kwargs.get("standard_logging_object", None), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1924, in _success_handler_helper_fn raise Exception(f"[Non-Blocking] LiteLLM.Success_Call Error: {str(e)}") Exception: [Non-Blocking] LiteLLM.Success_Call Error: 1 validation error for AnthropicResponse Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent

Code Example

uld be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent]\n    For further information visit https://errors.pydantic.dev/2.13/v/model_type')>
Traceback (most recent call last):
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1867, in _success_handler_helper_fn
    result = self._handle_anthropic_messages_response_logging(result=result)
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 3465, in _handle_anthropic_messages_response_logging
    pydantic_result = AnthropicResponse.model_validate(result)
  File "/app/.venv/lib/python3.13/site-packages/pydantic/main.py", line 732, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        obj,
        ^^^^
    ...<5 lines>...
        by_name=by_name,
        ^^^^^^^^^^^^^^^^
    )
    ^
pydantic_core._pydantic_core.ValidationError: 1 validation error for AnthropicResponse
  Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent]
    For further information visit https://errors.pydantic.dev/2.13/v/model_type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 2549, in async_success_handler
    start_time, end_time, result = self._success_handler_helper_fn(
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        start_time=start_time,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        standard_logging_object=kwargs.get("standard_logging_object", None),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1924, in _success_handler_helper_fn
    raise Exception(f"[Non-Blocking] LiteLLM.Success_Call Error: {str(e)}")
Exception: [Non-Blocking] LiteLLM.Success_Call Error: 1 validation error for AnthropicResponse
  Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Anthropic messages failed to handle spend log when stream is true。 spend log will not recorded, cost will failed too。

Steps to Reproduce

  1. request model in anthropic /v1/messages with stream is true
  2. example request: { "model": "xxx", "stream":true, "messages": [ { "role": "user", "content": "Hello, can you tell me a short joke?" } ], "max_tokens": 100 }
  3. spend log could not found in postgress or admin ui。and error message in litellm console: `uld be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent]\n For further information visit https://errors.pydantic.dev/2.13/v/model_type')> Traceback (most recent call last): File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1867, in _success_handler_helper_fn result = self._handle_anthropic_messages_response_logging(result=result) File "/app/litellm/litellm_core_utils/litellm_logging.py", line 3465, in _handle_anthropic_messages_response_logging pydantic_result = AnthropicResponse.model_validate(result) File "/app/.venv/lib/python3.13/site-packages/pydantic/main.py", line 732, in model_validate return cls.pydantic_validator.validate_python( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ obj, ^^^^ ...<5 lines>... by_name=by_name, ^^^^^^^^^^^^^^^^ ) ^ pydantic_core._pydantic_core.ValidationError: 1 validation error for AnthropicResponse Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent] For further information visit https://errors.pydantic.dev/2.13/v/model_type

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/app/litellm/litellm_core_utils/litellm_logging.py", line 2549, in async_success_handler start_time, end_time, result = self._success_handler_helper_fn( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ start_time=start_time, ^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... standard_logging_object=kwargs.get("standard_logging_object", None), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1924, in _success_handler_helper_fn raise Exception(f"[Non-Blocking] LiteLLM.Success_Call Error: {str(e)}") Exception: [Non-Blocking] LiteLLM.Success_Call Error: 1 validation error for AnthropicResponse Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent`

Relevant log output

uld be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent]\n    For further information visit https://errors.pydantic.dev/2.13/v/model_type')>
Traceback (most recent call last):
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1867, in _success_handler_helper_fn
    result = self._handle_anthropic_messages_response_logging(result=result)
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 3465, in _handle_anthropic_messages_response_logging
    pydantic_result = AnthropicResponse.model_validate(result)
  File "/app/.venv/lib/python3.13/site-packages/pydantic/main.py", line 732, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        obj,
        ^^^^
    ...<5 lines>...
        by_name=by_name,
        ^^^^^^^^^^^^^^^^
    )
    ^
pydantic_core._pydantic_core.ValidationError: 1 validation error for AnthropicResponse
  Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent]
    For further information visit https://errors.pydantic.dev/2.13/v/model_type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 2549, in async_success_handler
    start_time, end_time, result = self._success_handler_helper_fn(
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        start_time=start_time,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        standard_logging_object=kwargs.get("standard_logging_object", None),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/litellm/litellm_core_utils/litellm_logging.py", line 1924, in _success_handler_helper_fn
    raise Exception(f"[Non-Blocking] LiteLLM.Success_Call Error: {str(e)}")
Exception: [Non-Blocking] LiteLLM.Success_Call Error: 1 validation error for AnthropicResponse
  Input should be a valid dictionary or instance of AnthropicResponse [type=model_type, input_value=ResponseCompletedEvent(ty...=0), sequence_number=27), input_type=ResponseCompletedEvent

What part of LiteLLM is this about?

No response

What LiteLLM version are you on ?

1.87.rc.2

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Anthropic messages failed to handle spend log when stream is true