n4nAI

API integration

How-to

Debugging LLM API errors with Postman's console

Practical steps to debug LLM API errors Postman console: inspect requests, decode status codes, validate schemas, and verify gateway fallback for fast fixes.

n4n Team4 min read957 words

Audio narration

Coming soon — every post will get a voice note here.

When a chat completion call fails in production, the SDK stack trace rarely shows the wire-level truth. To debug LLM API errors Postman console gives you a request/response inspector that strips away client library abstractions. This guide walks through reproducing failures, reading the console timeline, and fixing the top classes of integration bugs without guessing.

Step 1: Create a scoped environment

Never hardcode credentials in the request builder. Create a Postman environment with two variables: baseUrl and apiKey. Keep the key referenced as {{apiKey}} so it never lands in exported collections.

{
  "baseUrl": "https://api.openai.com/v1",
  "apiKey": "sk-..."
}

If you proxy through a gateway, set baseUrl to the gateway’s OpenAI-compatible path. Select the environment from the top-right dropdown before sending anything. A wrong environment is the silent killer: Postman will send {{apiKey}} literally if the variable is undefined, and the console is the only place that exposes it.

Step 2: Build a minimal chat completion request

Start with the smallest payload that triggers the bug. If your app uses streaming, function calls, or custom parameters, strip them. A bare chat/completions call removes variables from the equation.

Set method to POST, URL to {{baseUrl}}/chat/completions. In the Headers tab:

Key Value
Authorization Bearer {{apiKey}}
Content-Type application/json

In the Body tab, choose raw and JSON:

{
  "model": "gpt-4o-mini",
  "messages": [
    {"role": "user", "content": "Say hello."}
  ],
  "temperature": 0.7
}

Send it once to confirm the happy path works. If this succeeds, layer complexity back in until the error returns. Bisecting the payload this way beats reading docs cold.

Step 3: Open the console and capture the timeline

The core technique to debug LLM API errors Postman console is the Console panel (Cmd/Ctrl+Alt+C). Open it before clicking Send. The console logs every request with full headers, resolved variables, and the raw response—including bodies that the UI truncates.

After sending, expand the entry. You will see:

  • Request: final URL after variable substitution, outgoing headers, and pretty-printed body.
  • Response: status, time, response headers, and body.
  • Network: redirects or proxy hops if any.

When you debug LLM API errors Postman console reveals the exact 401 or 429 body that a Python openai wrapper often collapses into a generic exception. Copy the raw response body from here into a scratch file for diffing against the docs. Also check the resolved request: if you see Authorization: Bearer {{apiKey}} unsubstituted, the environment is not active—fix that first.

Step 4: Decode status codes and error shapes

LLM providers broadly follow the OpenAI error envelope. A 400, 401, 429, or 500 each means something different:

  • 400 invalid_request_error: schema violation. Common causes: unknown model string, max_tokens as a string instead of int, or missing messages.
  • 401 invalid_api_key: key missing, malformed, or revoked. Check the resolved Authorization header in the console.
  • 429 rate_limit_exceeded: inspect the Retry-After response header. If you see this consistently at low volume, your key may be on a free tier or you are sharing it across workers.
  • 500/502 api_error: provider-side degradation. The console shows the upstream HTML or JSON blob.

Example 401 body from the console:

{
  "error": {
    "message": "Incorrect API key provided: sk-***. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

If the console shows a 200 but the body looks wrong (e.g., empty choices), your request likely hit a fallback model. That is where gateway headers matter.

Step 5: Validate request schema against the provider

SDKs sometimes serialize enums differently than the REST contract expects. Open the console request body and check types:

  • temperature, top_p, max_tokens must be numbers.
  • messages must be an array of objects with role and content.
  • model must be a string exactly matching a deployed model ID.

A frequent bug: passing max_tokens: "1024". The console will show the quoted string. Fix it in the JSON body:

{
  "model": "gpt-4o-mini",
  "messages": [{"role": "user", "content": "Say hello."}],
  "max_tokens": 1024
}

Resend and watch the console. If the status flips to 200, you found the bug. Do not trust your IDE’s autocomplete—trust the wire.

Step 6: Inspect streaming responses

Set "stream": true and send. The response Content-Type becomes text/event-stream. The Postman console shows each SSE frame as raw text, which is invaluable when your client hangs on a partial frame.

data: {"choices":[{"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"choices":[{"delta":{"content":"!"},"finish_reason":null}]}

data: [DONE]

If you see data: lines but your app throws on parse, the bug is client-side JSON extraction, not the API. The console proves the server behaved. Note that Postman may buffer the stream; if you need frame-by-frame timing, use curl --no-buffer alongside.

Step 7: Test gateway routing and fallback

When you route through an OpenRouter-class gateway, you gain automatic fallback when a provider is rate-limited. Gateways such as n4n.ai honor client routing directives, forward provider cache-control hints, and return per-token usage metering; the console exposes those headers so you can confirm a fallback and reconcile cost.

Send a request with a routing header:

{
  "model": "anthropic/claude-3.5-sonnet",
  "messages": [{"role": "user", "content": "Test"}]
}

Add a header x-router-directive: provider=anthropic. In the console response headers, look for x-cache-status, x-fallback-used: true, or usage meters. If the primary provider returned 429, the gateway retries another provider and the console shows the second attempt’s latency. This visibility is impossible from a bare SDK call.

Step 8: Automate the check with a test script

Manual console inspection scales poorly. Add a Postman Tests tab script to assert the error contract:

pm.test("response is well-formed", () => {
  const code = pm.response.code;
  if (code === 200) {
    const body = pm.response.json();
    pm.expect(body).to.have.property('choices');
  } else {
    const body = pm.response.json();
    pm.expect(body).to.have.nested.property('error.type');
    console.log('Error type:', body.error.type);
  }
});

Run the collection with Newman in CI to catch regressions in your request shape. The console output from CI mirrors your local view, so the debug loop stays identical.

Verify success

You have reproduced the failure in Postman, opened the console, matched the status code to the error envelope, corrected the schema or auth, and observed a 200 with valid choices. For streaming, you saw clean data: frames ending with [DONE]. For gateway routing, response headers confirmed fallback or cache hits.

Success looks like this: the console shows a single request, 200 OK, application/json body containing {"id":"chatcmpl-...","choices":[{"message":{"role":"assistant","content":"Hello."}}]}. If you can paste that raw request from the console into a team channel and have another engineer reproduce it, the bug is closed.

Keep the Postman collection in version control. The next time an LLM call breaks, you will debug LLM API errors Postman console in minutes instead of reading framework source.

Tagspostmandebuggingerror-handlingtesting

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →