Anthropic on universal Gateway

import requests
import json

def test_anthropic_api():
    messages = [
        {"role": "user", "content": "Hello, world"}
    ]
    data = [
        {
            "provider": "anthropic",
            "endpoint": "v1/messages",
            "headers": {
                "x-api-key": "YOUR_ANTHROPIC_API_KEY",
                "anthropic-version": "2023-06-01",
                "content-type": "application/json",
            },
            "query": {
                "model": "claude-3-opus-20240229",
                "messages": messages,
                "max_tokens": 500
            }
        }
    ]
    response = requests.post(
        "https://gateway.ai.cloudflare.com/v1/YOUR_ACCOUNT_TAG/YOUR_GATEWAY",
        headers={"Content-Type": "application/json"},
        json=data
    )
    response.raise_for_status()
    print(json.dumps(response.json(), indent=4))

if __name__ == "__main__":
    test_anthropic_api()


Still getting the same raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url
Was this page helpful?