Anthropic API authentication error in HTTP Request node — self-hosted n8n on Docker

Hey!

Describe the problem/error/question

Anthropic API authentication error in HTTP Request node — self-hosted n8n on Docker
I’m running self-hosted n8n on a VPS and trying to call the Anthropic API via HTTP Request node. I get “invalid x-api-key” authentication error both from the built-in Anthropic node and HTTP Request node with manual headers.

What is the error message (if any)?

Please share your workflow

Telegram Trigger → HTTP Request (api.anthropic.com/v1/messages) → Telegram reply

Share the output returned by the last node

{“type”:“error”,“error”:{“type”:“authentication_error”,“message”:“invalid x-api-key”}}

Information on your n8n setup

n8n version: latest (Docker)
Database: SQLite (default)
Running on: VPS Hostinger, Ubuntu 25.10, Docker 28.2.2
Launch command: docker run -d --restart always --name n8n -p 5678:5678 -e N8N_SECURE_COOKIE=false -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

1 Like

Hi @Alexey2 Welcome!
Make sure you are sending the correct request:

and try using the predefined credential type , and also make sure what you are sending with HTTP node is working with test in Postman or some kind of API tester, and also try using the native anthropic node and see how that works.

In the HTTP Request node, make sure you’re setting the header as x-api-key (not Authorization Bearer). Also add anthropic-version: 2023-06-01 as a second header. If you’re using the built-in Anthropic credential instead, check that the key doesn’t have leading/trailing whitespace - copy-paste from the Anthropic console sometimes adds invisible characters.

The previous replies cover the header setup well. One thing worth adding for self-hosted Docker setups: the most common cause of “invalid x-api-key” specifically (as opposed to “missing_api_key”) is that the key is being transmitted but the value is wrong or malformed.

A few things to check:

Test the key directly from your VPS before touching n8n. SSH in and run:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: YOUR_KEY_HERE" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-3-haiku-20240307","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'

If this curl fails from the VPS itself, the issue is your API key, not n8n at all. Check the Anthropic console to verify the key is active and has not been revoked.

If your key is stored as an environment variable in Docker, check your docker-compose.yml for quoting issues. Keys with special characters can get mangled. For example ANTHROPIC_API_KEY="sk-ant-..." needs proper quoting and the variable must actually be passed into the n8n container with the env: block, not just set on the host.

Also confirm your key starts with sk-ant-api03- (newer format) rather than the older sk-ant- format, as there were brief periods where some accounts had key format mismatches.

If you are using the built-in Anthropic credential type in n8n, try deleting and recreating the credential from scratch, then re-enter the key manually character by character rather than pasting. Invisible characters from the Anthropic console copy have bitten quite a few people.