Postman OpenAI API Test: 5 Steps for Env, Auth and Body (Apifox)
To test an OpenAI-compatible endpoint in Postman, you only need one POST request: set the URL to {{base_url}}/chat/completions, add the header Authorization: Bearer {{api_key}}, choose raw + JSON for the body, and fill in model and messages. Apifox works almost the same way; its environment variables live under "Environment" as a "Base URL" and "Variables". The steps below go in order, followed by an error lookup table.
The advantage of testing the OpenAI API in Postman first is that you can ignore SDK versions and your code environment and directly confirm three things: the key, the address, and the model name. Once a request works, you move it into code, and the space of things that can go wrong is much smaller.
Why test with a GUI tool before writing code?
When code fails, it is hard to tell whether the key is invalid, the network is unreachable, or an SDK parameter is wrong. A GUI tool splits the request into visible parts: URL, headers, body, status code, response. You can change each one on its own, and what you see is what the server actually returned.
If you don't have a key yet, start with How to get an OpenAI API key: the Platform dashboard, step by step. To understand why the request body looks the way it does, see What is the Chat Completions API? How to write the messages array.
How do I set things up in Postman, step by step?
Step 1: Create an environment and variables
Create a new Environment and add these variables:
| Variable | Example value | Notes |
|---|---|---|
base_url | https://api.openai.com/v1 | When you switch to a compatible gateway, change only this |
api_key | your key | Set the type to secret so it isn't shown in plain text in the UI |
model | Use your provider's model list | Don't write model names from memory |
Select this environment in the top-right corner. Don't write a real key into the request itself or sync it to a public Collection. If it does leak, see Your OpenAI API key leaked: revoke it now, check usage, and prevent a repeat.
Step 2: Create the request
Choose POST and enter this URL:
{{base_url}}/chat/completions
Step 3: Add the auth header
Add two lines under Headers:
Authorization: Bearer {{api_key}}
Content-Type: application/json
You can also pick Bearer Token on the Authorization tab and enter {{api_key}} as the value; the effect is the same. Make sure there are no spaces or line breaks before or after the key. That is the most common problem when copying and pasting.
Step 4: Write the request body
Choose raw for Body, and JSON as the format:
{
"model": "{{model}}",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what DNS is in one sentence."}
],
"max_tokens": 200
}
Keep max_tokens small at first; it costs less while you debug. For what each parameter means, see Your first LLM request with curl: every parameter explained line by line. The request body there is the same thing as here.
Step 5: Send and read the response
Click Send. On success the status code is 200, the reply text is in choices[0].message.content, and token usage is in usage. Confirm this one request works before you change anything else.
What is different in Apifox?
The approach is the same; only the UI wording differs:
- Under "Environment management", create an environment and set a "Base URL". Enter
https://api.openai.com/v1there, and write only/chat/completionsas the request path. - You can keep the key in an environment variable and write
Bearer {{api_key}}in the header. - Apifox requests can be saved as API documentation and reused in automated tests, which suits team collaboration. For exact menu locations and features, refer to the official Apifox documentation.
What if I want to see streaming output?
Add "stream": true to the request body, and the server returns the response as SSE (server-sent events, one data: line at a time). How a regular HTTP response panel displays streams varies by version: some wait until the whole response finishes and show it all at once, while others can show it chunk by chunk. Check whether your version supports live display of SSE responses, and go by the official documentation. If you only want to verify that the stream switch took effect, curl with the -N flag is more direct.
What do I check when I get an error?
| Symptom | Common cause | What to check first |
|---|---|---|
| 401 | Wrong, expired or revoked key; malformed header | Is there exactly one space after Bearer? Any extra characters in the key? |
| 403 | The account or region has no access, or insufficient permissions | Go by the provider's docs and dashboard messages |
| 404 | Wrong path or base_url | Did you add or omit /v1? Is the address being joined twice? |
| 400 | Invalid JSON or invalid parameters | Is Body set to JSON? Does the model name exist? |
| 429 | Too many requests, or quota used up | Read the error message in the response body; for usage and limits see How to set a spending limit and usage alerts for the OpenAI API |
| 5xx | Server-side problem | Retry later and check the official status page |
| No response for a long time | Network or proxy problem | Check proxy settings, see the next section |
For a 5xx or a timeout, first look at cdnping's OpenAI status page. It probes the official API endpoint from the Cloudflare edge every 5 minutes, which helps you tell whether the problem is on the server side.
What do I change when I switch to a compatible gateway?
As long as the gateway is compatible with the OpenAI format, you usually change only base_url, api_key and model in the environment variables; the request itself stays the same. For exact addresses and model names, go by the relevant provider's documentation. When you need connectivity and latency reference points, you can use the cdnping online speed test to see first-connection and round-trip times for each provider's API endpoint in your browser.
One more thing: the Postman desktop app has its own proxy settings and may follow the system proxy by default. If a request works in the browser but not in Postman, check the Proxy section in Settings first.
Just starting out: do I need to get my own key and overseas payment?
If your goal is to get a large model running in tools like Claude Code or Codex as quickly as possible, you could look at AGI Plan. It is a multi-provider LLM aggregation gateway with monthly subscriptions, payment in RMB, and no overseas credit card required. With Claude Code or Codex you only change one endpoint address, and a single subscription can switch between multiple capability groups. It is compatible with both the OpenAI and Anthropic API formats, so you can try the Postman workflow above by swapping in its base_url and key. Some models are available only outside mainland China; see the AGI Plan models page for specifics. It is not an officially authorized channel. AGI Plan is a commercial partner of cdnping. For setup steps, see the AGI Plan quick start.
For where to enter the address in each tool, see Custom API endpoints for Claude Code, Codex and OpenCode.
What should I do next?
- Follow the 5 steps above and get one 200 response in Postman or Apifox.
- Export the request as a code snippet, or turn it into a script using Calling an LLM API from Node.js: a minimal working example.
- Set a spending limit in the provider's dashboard before you start debugging repeatedly.
If you are calling Anthropic's API, the auth header, path and version header are all different (it uses x-api-key and anthropic-version). Go by Anthropic's official documentation, and don't reuse the headers above as they are.