How to Test an API Endpoint With 3 curl Commands (2026)
Three curl commands are enough to tell whether an API endpoint works. First confirm the domain resolves and the TLS handshake succeeds, then request /v1/models to validate your key, and finally send a chat request that asks for a single token. Whichever step fails tells you which layer is at fault: the network, authentication, or the model name.
This API endpoint test applies to OpenAI-compatible endpoints (addresses that look like https://example.com/v1), and the article also covers what to change for Anthropic's native format. The domains, keys, and model names in the examples are placeholders, so replace them with your own.
Why not just click "Test connection" in your tool?
The "Test connection" button in tools like Cherry Studio, Cline, and Cursor often shows only "failed" or "network error" when something goes wrong. You can't tell whether the domain is unreachable, the key is wrong, or the model name is off.
The command line lets you inspect each layer separately. This table gives an overview of the whole process:
| Step | What it does | What it rules out |
|---|---|---|
| 1 | Measure DNS, TCP, and TLS timing | Network, certificates, proxy |
| 2 | GET /v1/models | Base path, API key, permissions |
| 3 | POST one minimal chat request | Model name, quota, request format |
Command 1: Is the network layer reachable?
Start with the stretch from domain lookup to TLS handshake. Use curl's -w option to print the timing of each phase:
curl -sS -o /dev/null -w "dns=%{time_namelookup}s connect=%{time_connect}s tls=%{time_appconnect}s total=%{time_total}s code=%{http_code}\n" https://example.com/v1/models
No key is sent here, so a 401 is expected and means the request reached the server. Reading the result:
code=401or403: the network is fine, move on to step 2.- The command hangs or times out: look at the
dnsandconnectvalues in the output. Adnsof 0 usually means resolution failed; ifdnslooks normal butconnectis 0, the TCP connection was never established. SSL_ERROR_SYSCALL, certificate errors, and the like: these are TLS-layer problems. Work through curl SSL_ERROR_SYSCALL: TLS handshake failures when calling AI APIs item by item.- Your terminal goes through a proxy and results look odd: check whether curl is picking up the
HTTPS_PROXYenvironment variable, and if needed add--noproxy '*'to compare against a direct connection.
If you'd rather not open a terminal, you can also pick the relevant AI API on the cdnping homepage speed test and look at "first connection" (which includes DNS and the TLS handshake) and "round trip". That measurement is made from your browser and only covers the 15 APIs already on the list, so self-hosted gateways and third-party endpoints aren't included and still need the commands above. To check whether an official API is having a wider problem, see the API status page.
Command 2: Are the key and path correct?
/v1/models is the cheapest validation request in the OpenAI-compatible API, and it doesn't consume quota (check your provider's documentation to be sure):
curl -sS -i https://example.com/v1/models \
-H "Authorization: Bearer $API_KEY"
Put the key in an environment variable named API_KEY rather than pasting it into the command, so it doesn't end up in your shell history.
Common causes for each status code:
| Response | Common cause | Next step |
|---|---|---|
| 200 with a model list | Endpoint and key are both fine | Go to step 3 and note a model ID from the list |
| 401 | Wrong or expired key, or stray spaces or newlines | See 401 Invalid API Key: 6 things to check |
| 403 | The key lacks permission for this endpoint, or access is restricted by origin | Check the key's permission settings with your provider |
| 404 | Wrong path, often an extra or missing /v1 | Confirm the base URL against the provider's docs |
| An HTML page | The request hit the website instead of the API | Check the domain and path |
Some providers don't offer /v1/models and return 404. That doesn't mean the endpoint is unusable, so just go straight to step 3.
Command 3: Can it actually hold a conversation?
Send a minimal request and cap the output at a few tokens:
curl -sS -i https://example.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"MODEL_ID","messages":[{"role":"user","content":"ping"}],"max_tokens":8}'
Take MODEL_ID straight from the list returned in step 2. Some providers use paths like /v1/responses for their newer endpoints, so follow the official docs for parameters.
Interpreting the result:
- 200 with
choices: the whole chain works. If your tool still fails, the problem is most likely in the tool's configuration, for example a base URL that wrongly includes/chat/completions. - 404 or
model not found: the model name is wrong. See model not found / 404: what to put in the model field. - 429: tell rate limiting apart from insufficient quota. See 429 Too Many Requests: what to do.
- 400: usually a field in the request body isn't accepted. Read
error.messagein the response. - 5xx: a problem on the provider's side, so retry later. For what each status code means and whether to retry, see the error code cheatsheet.
What about Anthropic's native format?
Anthropic's native API doesn't use Authorization: Bearer. It uses an x-api-key header and also requires an anthropic-version header. The chat path is /v1/messages, and max_tokens is required. Check Anthropic's official documentation for the exact version number and fields. The three-step approach stays the same: network layer, authentication, minimal chat.
If it still fails, what should you collect before asking for help?
When you ask the provider's support or a community for help, including these items saves a lot of back and forth:
- The full output of command 1 (just redact any private parts of the domain).
- The status codes and
errorfields returned by commands 2 and 3, with the key always masked. - Your network environment: direct connection, corporate network, or through a proxy.
- The time you ran the commands, so the other side can match it against their logs.
New to APIs? How to avoid common detours
Beginners often get stuck on prerequisites such as an overseas credit card or account region rather than on the commands themselves. If you want to get the workflow running first, you can look into AGI Plan. It is a multi-provider LLM aggregation gateway with monthly subscriptions, paid in RMB, and no overseas credit card needed. Tools such as Claude Code and Codex only need an endpoint change to reach several capability groups under one shared quota. Some models are marked "overseas only"; see the AGI Plan models page for specifics. The service states that it is not an officially authorized channel. AGI Plan is a commercial partner of cdnping, and the getting-started steps are at agiplan.dev/startup.
Whenever you get a new endpoint, run the three commands in this article once each before filling it into a tool. To keep an eye on overall network and API conditions over time, bookmark the developer network self-check checklist as well.