Skip to content

Anthropic through vertex does not forward header properly #1345

@xiang-deng

Description

@xiang-deng

What Happened?

There seems to be some issue when calling claude models through vertex_ai. To unify things, I am calling everything through the official anthropic sdk. In particular I am trying to access the computer_use tool, which require passing the additional anthropic_beta header.

What works:

  • Use the anthropic API with anthropic endpoint
client = anthropic.Anthropic(api_key="dummy", base_url="https://api.portkey.ai/v1")

response = client.beta.messages.create(
    model="@anthropic-default/claude-sonnet-4-20250514",  # or another compatible model
    max_tokens=1024,
    tools=[
        {
          "type": "computer_20250124",
          "name": "computer",
          "display_width_px": 1024,
          "display_height_px": 768,
          "display_number": 1,
        },
        {
          "type": "text_editor_20250124",
          "name": "str_replace_editor"
        },
        {
          "type": "bash_20250124",
          "name": "bash"
        }
    ],
    messages=[{"role": "user", "content": "Save a picture of a cat to my desktop."}],
    betas=["computer-use-2025-01-24"],
    extra_headers=createHeaders(
        api_key=xxx,
        config=json.dumps(
            {
                "strategy": {"mode": "fallback"},
                "targets": [
                    {
                        "override_params": {
                            "model": "@anthropic-default/claude-sonnet-4-20250514",
                        },
                    }
                ],
            }
        ),
    ),
)
print(response)

What does not work

client = anthropic.Anthropic(api_key="dummy", base_url="https://api.portkey.ai/v1")

response = client.beta.messages.create(
    model="@anthropic-default/claude-sonnet-4-20250514",  # or another compatible model
    max_tokens=1024,
    tools=[
        {
          "type": "computer_20250124",
          "name": "computer",
          "display_width_px": 1024,
          "display_height_px": 768,
          "display_number": 1,
        },
        {
          "type": "text_editor_20250124",
          "name": "str_replace_editor"
        },
        {
          "type": "bash_20250124",
          "name": "bash"
        }
    ],
    messages=[{"role": "user", "content": "Save a picture of a cat to my desktop."}],
    betas=["computer-use-2025-01-24"],
    extra_headers=createHeaders(
        api_key=PORTKEY_KEY,
        config=json.dumps(
            {
                "strategy": {"mode": "fallback"},
                "targets": [
                    {
                        "override_params": {
                            # "model": "@anthropic-default/claude-sonnet-4-20250514",
                            "model": "@gcp-vertex-default/anthropic.claude-sonnet-4@20250514",
                        },
                    }
                ],
            }
        ),
    ),
)
print(response)

This will lead to endpoint not found error.

  • however if we remove the v1
client = anthropic.Anthropic(api_key="dummy", base_url="https://api.portkey.ai")

response = client.beta.messages.create(
    model="@anthropic-default/claude-sonnet-4-20250514",  # or another compatible model
    max_tokens=1024,
    tools=[
        {
          "type": "computer_20250124",
          "name": "computer",
          "display_width_px": 1024,
          "display_height_px": 768,
          "display_number": 1,
        },
        {
          "type": "text_editor_20250124",
          "name": "str_replace_editor"
        },
        {
          "type": "bash_20250124",
          "name": "bash"
        }
    ],
    messages=[{"role": "user", "content": "Save a picture of a cat to my desktop."}],
    betas=["computer-use-2025-01-24"],
    extra_headers=createHeaders(
        api_key=PORTKEY_KEY,
        config=json.dumps(
            {
                "strategy": {"mode": "fallback"},
                "targets": [
                    {
                        "override_params": {
                            "model": "@gcp-vertex-default/anthropic.claude-sonnet-4@20250514",
                        },
                    }
                ],
            }
        ),
    ),
)
print(response)

Now portkey stops forwarding the anthropic_beta header. From the log I can see the original request has the header, but the final transformed one removed it. And even with things like forward_headers set, the header is still not forwarded

What Should Have Happened?

No response

Relevant Code Snippet

No response

Your Twitter/LinkedIn

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions