For the complete documentation index, see llms.txt. This page is also available as Markdown.

Request routing and redirects

How a request to the Consumption API gets to the supplier fulfilling your inference, and which clients need configuration to follow the routing redirect.

When you send a request to the Consumption API, we validate your balance and forward the request to the routing layer that fulfills inference. The API responds with an HTTP 307 Temporary Redirect, and the Location header contains the target URL.

Your HTTP client needs to follow the redirect and re-send the same HTTP method (POST), request body, and Authorization header to the redirect target. This is standard HTTP behavior defined in RFC 7231 Section 6.4.7.

Most clients follow 307 by default

If you use any of these libraries, no configuration is needed. The redirect happens transparently:

  • Python requests

  • Python httpx (with default settings)

  • Node.js fetch

  • Node.js axios

  • Go net/http

  • OpenAI SDK (Python and Node)

  • Anthropic SDK (against the messages-beta host)

The 307 happens, the client follows it, the inference completes, and your code sees a normal 200 response with the model output. You don't see the redirect in application logs unless you specifically inspect HTTP traffic.

cURL needs -L

cURL doesn't follow redirects by default. Pass -L:

curl -L -X POST https://api.thegrid.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "text-prime", "messages": [{"role": "user", "content": "Hello"}]}'

Without -L, cURL returns the 307 response itself instead of following it through to the supplier. You see a 307 status, the Location header, an empty body, and your inference doesn't run.

Clients that need configuration

A few clients don't follow redirects by default, or have configurations that disable it:

  • httpx.Client(follow_redirects=False): explicitly disabled. Set follow_redirects=True or use the default.

  • urllib.request in Python: doesn't follow 307 for POST automatically. Use requests or httpx instead, or implement the follow manually.

  • Some hand-rolled HTTP clients in low-level languages.

  • Browser fetch with redirect: 'manual' or redirect: 'error'.

If your code receives a raw 307, the fix is on the client side: toggle redirect-following on.

Where the redirect points

The 307 sends your client to https://api.thegrid.ai/r/v1/ — the same host as the initial request, with /r/ added to the path. The routing layer fulfills inference from there.

Firewall and domain allowlisting

If your environment restricts outbound HTTP traffic (common for agent frameworks running in sandboxed environments and enterprise deployments behind a strict outbound allowlist), api.thegrid.ai is the only domain you need to allowlist. The initial request and the redirect target both live on it.

307 is not an error

The 307 is our routing layer doing its job. We document it alongside error codes only because clients without redirect-following see it surface as a non-200 response. See Errors and rate limits for the full status code catalog.

Last updated

Was this helpful?