Last updated
Mistral Base URL API Timeout: Fix 404, 405 and Hangs
A mistral base url api timeout after you switch endpoints almost always has one of three causes: a wrong path, a redirect that turns your POST into a GET, or a long generation hitting a short timeout. This page shows how to tell them apart and what to change, using the OpenAI SDK against https://api.mistralbaseurl.com/v1.

Start with the status code
The fastest triage is to look at what you actually received. Run the request with curl and -i to see the status line.
| Symptom | Likely cause | First fix |
|---|---|---|
| 404 Not Found | Path is wrong: missing or doubled /v1, typo in the endpoint | Compare your URL with https://api.mistralbaseurl.com/v1/chat/completions |
| 405 Method Not Allowed | GET sent to a POST endpoint, or a redirect changed POST to GET | Use https and POST for chat calls |
| 401 | Missing or malformed key | Send Authorization: Bearer YOUR_API_KEY with no stray spaces |
| 429 | Request or concurrency limit, or temporary overload | Wait, then retry with backoff |
| No response, then a client error | Timeout in your client, proxy or load balancer | Stream the response and raise the read timeout |
Only the last row is a real timeout. The others fail fast, so if a request takes a long time and then dies, look at the timeout path first.
404: the URL is slightly off
The base URL is https://api.mistralbaseurl.com/v1. The SDK adds /chat/completions for you. These mistakes all produce a 404:
https://api.mistralbaseurl.com/chat/completions(no/v1)https://api.mistralbaseurl.com/v1/v1/chat/completions(base already had/v1and the code added it again)https://api.mistralbaseurl.com/v1/chat/completion(missing the final s)- A base URL that ends in
/chat/completions, which the SDK extends a second time
Test the base with the lightest endpoint available:
curl -i https://api.mistralbaseurl.com/v1/models \
-H "Authorization: Bearer $API_KEY"A 200 with a model list means the base and key are right. If this works and chat fails, the problem is the chat path or the body. Our integration guide covers the full request shape.
405: wrong method, or a redirect that rewrote it
Chat completions, responses and most other calls are POST. Opening the chat URL in a browser sends a GET and returns an error by design, which is not a fault.
The sneakier case is a redirect. If your base URL starts with http://, the request may be redirected to https. Many HTTP clients follow a 301 or 302 redirect by switching a POST into a GET and dropping the body, and the target then answers 405. Always write https://. Also check that no proxy or URL rewriter in front of your app is issuing redirects. Running curl with -i and no redirect following shows any Location header.
Timeouts on long generations
The context window is 100,000 tokens, and a completion can use the rest of it when you set no max_tokens. A long answer takes real time. With a non-streamed request the client waits silently until the whole completion is finished, so any component that gives up after N seconds of silence will kill it. The nginx default for proxy_read_timeout is 60 seconds, and many CDNs and load balancers use limits in the same range.
The standard remedy is streaming. With stream: true the server sends tokens as they are produced, so the connection is never idle. Your read timeout then measures the gap between chunks, not the total length of the answer. Streaming also means users see text sooner.
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Write a long story about a lighthouse."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)If you cannot stream, cap the length with max_tokens so the response fits inside your shortest timeout.
Set timeouts and retries on purpose
SDK defaults are generic. Set your own, with a short connect timeout so dead addresses fail fast and a longer read timeout for generation.
import httpx
from openai import OpenAI
client = OpenAI(
base_url="https://api.mistralbaseurl.com/v1",
api_key="YOUR_API_KEY",
timeout=httpx.Timeout(connect=10.0, read=90.0, write=30.0, pool=10.0),
max_retries=3,
)
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "ping"}],
max_tokens=5,
)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.mistralbaseurl.com/v1",
apiKey: process.env.API_KEY,
timeout: 90 * 1000,
maxRetries: 3,
});
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "ping" }],
max_tokens: 5,
});The OpenAI SDKs retry connection errors, 408, 409, 429 and 5xx responses with a short exponential backoff. That is fine for most apps. Retrying a timed-out non-streamed request repeats the generation, so keep retries low for very long outputs. With curl, use --connect-timeout 10 --max-time 120 to avoid hanging scripts.
A script that names the failure
When errors are intermittent, let code classify them for you. This script maps the SDK's exception types to the causes above and prints the request ID when one exists.
import openai
from openai import OpenAI
client = OpenAI(
base_url="https://api.mistralbaseurl.com/v1",
api_key="YOUR_API_KEY",
max_retries=0,
timeout=30,
)
try:
r = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "ping"}],
max_tokens=5,
)
print("ok", r.choices[0].message.content)
except openai.NotFoundError:
print("404: check the base URL and path")
except openai.AuthenticationError:
print("401: check the key")
except openai.RateLimitError as e:
print("429: wait", e.response.headers.get("Retry-After", "a few"), "seconds")
except openai.APITimeoutError:
print("timeout: stream the response or raise the read timeout")
except openai.APIConnectionError:
print("connection failed: DNS, firewall or proxy")
except openai.APIStatusError as e:
print("status", e.status_code, e.response.headers.get("X-Request-Id"))Order matters: APITimeoutError is a subclass of APIConnectionError, so it must come first. Include the request ID from X-Request-Id if you contact support.
Platforms and proxies with their own limits
If the script above works from your laptop but your deployed app still hangs, the platform is usually the cause. Serverless functions and managed hosts often cap how long a single invocation may run, and reverse proxies enforce idle timeouts. A 90-second generation inside a function limited to 30 seconds will fail every time, and the error will not mention the API at all.
Three fixes cover most cases. Stream the answer through your server so data keeps moving. Move long jobs to a background worker and let the browser poll for the result. Or lower max_tokens so the answer finishes in time. Check the documentation of your host for its maximum request duration and make sure your streaming route is not buffered by a proxy; some proxies hold back chunks until a buffer fills, which makes a stream look like a hang.
Once the path works, you can add credit on the API key page and keep the same settings.
A 429 is a limit, not a timeout
If requests fail quickly with HTTP 429, you hit a limit. The error code rate_limited means too many requests per minute and concurrency means too many at once. A full key allows 8 concurrent requests and 300 per minute; a trial key allows 2 and 60. On temporary overload the API also answers 429 with a Retry-After: 5 header, so wait five seconds and try again.
One detail catches people who stream: a streamed request holds its concurrency slot until the stream ends. A stream you abandon without closing, for example after the user navigates away, keeps the slot busy, so close it. Details are in the docs.
Checklist when nothing works
- Run
GET /v1/modelswith curl. If it fails, fix URL or key. - Confirm https and the exact path.
- Send a tiny chat request with
max_tokens: 20. If that succeeds, the problem is length or timeouts. - Switch to streaming and raise the read timeout.
- Look at any proxy between you and the API for idle limits.
More guides
Common questions
Why do I get a 404 after changing the base URL?
Usually the path is off. The base should be https://api.mistralbaseurl.com/v1, with no extra /v1 and no /chat/completions at the end.
Why does a 405 appear when my code uses POST?
An http base URL can be redirected, and many clients turn the redirected POST into a GET. Use https:// from the start.
How do I stop long answers from timing out?
Use stream: true so data keeps flowing, raise the read timeout, and consider setting max_tokens.
Is a 429 a timeout?
No. It means a limit was reached or the service is briefly overloaded. Wait for the Retry-After seconds and retry.
Get your API key now
Sign up, grab your key, update your base URL. That is all.