Skip to content

Not connecting with Anthropic API for picture description #132

@paulohss

Description

@paulohss

Hi all!

I'm trying to use Claude Sonnet to add descriptions to the images on PDFs with the following code:

api_key = "sk-ant-api03-YOUR_ACTUAL_KEY_HERE"
model = "claude-sonnet-4-5-20250929"

picture_desc_api_option = PictureDescriptionApiOptions(
    url="https://api.anthropic.com/v1/messages",
    prompt="Describe this image in sentences in a single paragraph.",
    params=dict(
        model=model,
        max_tokens=1024,
        messages=[],  # Docling might need this structure
    ),
    headers={
        "x-api-key": api_key,
        "anthropic-version": "2023-06-01",
        "Content-Type": "application/json",
    },
    timeout=60,
)

When I run, it gives this error:
HTTPError: 400 Client Error: Bad Request for url: https://api.anthropic.com/v1/messages

According to Anthropic:
A 400 Bad Request error means the API request format is incorrect. This is likely because Docling is formatting the request in a way that doesn't match Anthropic's API expectations, for example:

  • Missing required fields: Anthropic's API requires specific fields like the messages array
  • Image encoding: The image data might not be formatted correctly
  • Docling compatibility: Docling might be designed for OpenAI's format, not Anthropic's

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions