litellm - 💡(How to fix) Fix Anthropic message format validation doesn't reject unsupported image URL sources in /v1/messages endpoint [1 comments, 1 participants]

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…
GitHub stats
BerriAI/litellm#23025Fetched 2026-04-08 00:38:48
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
closed ×1commented ×1labeled ×1

Error Message

Expected: HTTP 400 with validation error (matching /v1/chat/completions behavior) Actual: Request passes proxy validation, fails at Anthropic with opaque error

  1. Inconsistent Error Messages — Same invalid request format succeeds validation in one endpoint but fails in another
  2. Delayed Error Detection — Client gets generic provider error instead of clear proxy validation feedback
  • /v1/messages with Anthropic + image URL source → HTTP 400 validation error
  • /v1/chat/completions with Anthropic + image URL source → HTTP 400 validation error (existing behavior)

Root Cause

  1. Inconsistent Error Messages — Same invalid request format succeeds validation in one endpoint but fails in another
  2. Delayed Error Detection — Client gets generic provider error instead of clear proxy validation feedback
  3. Proxy Value Proposition — LiteLLM's core purpose is to normalize provider differences; this inconsistency defeats that goal

Code Example

# This request is accepted by /v1/messages but fails when sent to Anthropic
curl -X POST http://localhost:4000/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3-sonnet-20240229",
    "messages": [{
      "role": "user",
      "content": [{
        "type": "image",
        "source": {
          "type": "url",
          "url": "https://example.com/image.jpg"
        }
      }]
    }],
    "max_tokens": 1024
  }'
RAW_BUFFERClick to expand / collapse

Problem

The /v1/messages endpoint accepts image URL sources without validating provider support, while /v1/chat/completions correctly rejects them with "URL sources are not supported". This inconsistency causes requests to fail downstream at the Anthropic API boundary instead of being caught at the proxy validation layer.

Current Behavior

# This request is accepted by /v1/messages but fails when sent to Anthropic
curl -X POST http://localhost:4000/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3-sonnet-20240229",
    "messages": [{
      "role": "user",
      "content": [{
        "type": "image",
        "source": {
          "type": "url",
          "url": "https://example.com/image.jpg"
        }
      }]
    }],
    "max_tokens": 1024
  }'

Expected: HTTP 400 with validation error (matching /v1/chat/completions behavior) Actual: Request passes proxy validation, fails at Anthropic with opaque error

Why This Matters

  1. Inconsistent Error Messages — Same invalid request format succeeds validation in one endpoint but fails in another
  2. Delayed Error Detection — Client gets generic provider error instead of clear proxy validation feedback
  3. Proxy Value Proposition — LiteLLM's core purpose is to normalize provider differences; this inconsistency defeats that goal

Expected Solution

Add provider capability checking in /v1/messages message validation (similar to existing /v1/chat/completions validation):

  1. Before accepting the request, inspect the image source type
  2. If source.type == "url" and provider doesn't support it (e.g., Anthropic), return HTTP 400 with message matching /v1/chat/completions: "URL sources are not supported"
  3. Ensure both endpoints enforce the same validation rules

Related

This appears related to #23016, which reports the same inconsistency. The fix should address both endpoints.

Testing

Validate that:

  • /v1/messages with Anthropic + image URL source → HTTP 400 validation error
  • /v1/chat/completions with Anthropic + image URL source → HTTP 400 validation error (existing behavior)
  • /v1/messages with providers that support image URLs (e.g., OpenAI) → request succeeds

Contributed by Klement Gunndu

extent analysis

Fix Plan

To address the inconsistency, we need to add provider capability checking in the /v1/messages endpoint. Here are the steps:

  • Update the validation logic for the /v1/messages endpoint to check the image source type.
  • If the source type is a URL and the provider does not support it, return an HTTP 400 error with a validation message.

Example code snippet in Python:

from flask import request, jsonify

# Define a function to check provider capabilities
def check_provider_capabilities(provider, source_type):
    # For example, Anthropic does not support URL sources
    if provider == "anthropic" and source_type == "url":
        return False
    # Add more provider capabilities as needed
    return True

# Update the /v1/messages endpoint to include validation
@app.route('/v1/messages', methods=['POST'])
def handle_messages():
    data = request.get_json()
    # Check the image source type
    for message in data['messages']:
        for content in message['content']:
            if content['type'] == 'image' and not check_provider_capabilities(data['model'], content['source']['type']):
                return jsonify({'error': 'URL sources are not supported'}), 400
    # If validation passes, proceed with the request
    # ...

Verification

To verify the fix, test the following scenarios:

  • Send a request to /v1/messages with Anthropic as the provider and an image URL source. The response should be an HTTP 400 error with a validation message.
  • Send a request to /v1/chat/completions with Anthropic as the provider and an image URL source. The response should still be an HTTP 400 error with a validation message (existing behavior).
  • Send a request to /v1/messages with a provider that supports image URLs (e.g., OpenAI) and an image URL source. The request should succeed.

Extra Tips

  • Ensure that the check_provider_capabilities function is updated to include capabilities for all supported providers.
  • Consider adding more robust error handling and logging to help with debugging and monitoring.

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