Skip to content

Error using anthropic.Anthropic(base_url) #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
baldantas opened this issue Feb 21, 2025 · 0 comments
Open

Error using anthropic.Anthropic(base_url) #239

baldantas opened this issue Feb 21, 2025 · 0 comments

Comments

@baldantas
Copy link

After installing docker with the command below:

docker run -e ANTHROPIC_BASE_URL=http://localhost:8080 -e ANTHROPIC_API_KEY=MY_KEY -v %userprofile%/.anthropic:/home/computeruse/.anthropic -p 5900:5900 -p 8501:8501 -p 6080:6080 -p 8080:8080 -it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest

And try to run the python script below:

import anthropic
from anthropic import APIConnectionError, APIStatusError
import requests

client = anthropic.Anthropic(api_key="MY_KEY_API",
                             base_url="http://localhost:8080"
                             )

try:
    response = client.beta.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1024,
        tools=[
            {
                "type": "computer_20241022",
                "name": "computer",
                "display_width_px": 1024,
                "display_height_px": 768,
                "display_number": 1,
            }
        ],
        messages=[
            {"role": "user", "content": "Tire um print da tela."},
            {"role": "user", "content": "Salve o print em /home/computeruse/screenshot.png"}
        ],
        betas=["computer-use-2024-10-22"],
    )
    print("Resposta do servidor:", response)

except requests.exceptions.ConnectionError:
    print("Erro: Não foi possível conectar ao servidor local. Verifique se o Docker está rodando.")
except APIConnectionError as e:
    print("O servidor não pôde ser alcançado")
    print(e.__cause__)
except APIStatusError as e:
    print("Erro de status recebido")
    print(e.status_code)
    print(e.response)

I get the following error when running the python script:

Erro: <!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error response</title>
    </head>
    <body>
        <h1>Error response</h1>
        <p>Error code: 501</p>
        <p>Message: Unsupported method ('POST').</p>
        <p>Error code explanation: 501 - Server does not support this operation.</p>
    </body>
</html>

Note:
I can access it successfully in the browser

Image

Anyone successfully using calling the docker framework via "base_url" successfully?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant