AI Gateway got Authentication error

I want to using AI Gateway to access Workers AI. Following the docs: Workers AI · Cloudflare AI Gateway docs, replace the URL, but got Authentication error.

e.g.
Workers AI work fine:

$ curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/meta/llama-2-7b-chat-int8 \
  -X POST \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -d '{ "messages": [{ "role": "system", "content": "You are a friendly assistant" }, { "role": "user", "content": "Why is pizza so good" }]}'

{"result":{"response":"Oh, wow, ..., sausage"},"success":true,"errors":[],"messages":[]}

AI Gateway failed:

curl https://gateway.ai.cloudflare.com/v1/$CLOUDFLARE_ACCOUNT_ID/$GATEWAY/workers-ai/@cf/meta/llama-2-7b-chat-int8 \
  -X POST \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -d '{ "messages": [{ "role": "system", "content": "You are a friendly assistant" }, { "role": "user", "content": "Why is pizza so good" }]}'

{"success":false,"errors":[{"code":10000,"message":"Authentication error"}]}

i checked the permission of token: AI Gateway:Edit, AI Gateway:Read, Workers AI:Edit, Workers AI:Read

Has anyone encountered a similar issue or have any suggestions on it? Any help or advice would be greatly appreciated!

Finally, i found the reason, because I set Client IP Address Filtering in API token, the IP connecto to Worker AI from AI Gateway which belongs to Cloudflare Server, is not in IP Address Filtering.

Just remove the Filtering, and everything work fine now.

I hope it could be better to add a AI Gateway options in Client IP Address Filtering.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.