Home → Help

405 Method Not Allowed when calling an AI API

Your POST reached the web server but not the API. The path you sent it to only answers GET, so the server rejects the method rather than the request. On almost every gateway this means the base URL stopped one segment short — it points at the site root instead of the API prefix.

What you are seeing

Why it happens

OpenAI-lineage SDKs do not add a path prefix for you. Whatever you put in base_url is used verbatim, with /chat/completions appended. Give them https://example.com and the request goes to https://example.com/chat/completions; give them the bare domain with a trailing slash and some clients collapse it to https://example.com/ — a plain POST to the homepage.

A homepage is static. It answers GET and HEAD and refuses everything else, which is exactly a 405. The request never reached any API code, so nothing appears in your usage log — and an empty log is itself the clue.

This is the mirror image of the Anthropic case. Claude Code and the Anthropic SDK append /v1/messages themselves, so they need the base URL WITHOUT /v1. Copying a working Claude Code setting into an OpenAI client reproduces this error every time.

Confirm it is this

Ask the server which methods that exact path accepts:

curl -s -o /dev/null -w '%{http_code}\n' -X POST 'YOUR_BASE_URL/chat/completions'
# and compare with the bare domain:
curl -s -D- -o /dev/null -X POST 'https://YOUR_DOMAIN/' | grep -i '^allow\|HTTP/'

If the bare domain answers 405 with an Allow: GET, HEAD header, you have found it. A correct API path returns 401 when the key is missing — an authentication error means you are talking to the API.

How to fix it

  1. Put the API prefix back on the base URLFor OpenAI-style clients the base URL has to end with the API prefix, normally /v1. The SDK adds /chat/completions after it, and nothing else.
  2. Do not reuse the Claude Code valueClients in the Anthropic lineage take the bare host because they append /v1/messages internally. The two settings look interchangeable and are not.
  3. Drop the trailing slashA base URL ending in / can produce a double slash, and some routers send that to the front-end instead of the API — same 405, same missing log entry.
ClientBase URL should be
OpenAI SDK (Python, Node, Go)ends with /v1
Codex, Cherry Studio, Chatbox, LobeChat, LM Studioends with /v1
Cursor, Cline, Roo Codeends with /v1
Anthropic SDKno /v1 — it appends /v1/messages
Claude Codeno /v1 — same reason
On APICLAN the base URL is https://apiclan.us/v1 for OpenAI-style clients and https://apiclan.us for Claude Code and the Anthropic SDK. Every client setting is listed in the quickstart.

Related

Unexpected token '<' when calling an OpenAI-compatible API401 invalid API key — when the key looks right but still fails

Last checked 2026-10-01. Written from problems diagnosed on a live OpenAI-compatible gateway, not collected from other sites.