Suanlimao
← Back to all tutorials

Connect your tools

curl and streaming

Test the API straight from the command line: chat, streaming and the model list.

About 6 minFor:Anyone checking that the API works or debugging

Before you start

  • A terminal
  • A key, first stored in an environment variable

Step 1 · STEP 0x01

Set the variables

terminal
$ export API_KEY=<YOUR_API_KEY>$ export BASE=https://api.suanlimao.shop/v1
The full key is shown only once, at creation. Missed it? Revoke it and create a new one.

Create a key →

Step 2 · STEP 0x02

List the models

terminal
$ curl -s $BASE/models -H "Authorization: Bearer $API_KEY"{"object":"list","data":[{"id":"…"}, …]}
The reply is an OpenAI-format model list. The model plaza is the reference: it shows whether each model is on sale and which APIs it supports.

Open the model plaza →

Step 3 · STEP 0x03

A normal chat request

terminal
$ curl -s $BASE/chat/completions \    -H "Authorization: Bearer $API_KEY" \    -H "Content-Type: application/json" \    -d '{"model":"<MODEL_NAME>","messages":[{"role":"user","content":"Hello"}]}'{"choices":[{"message":{"content":"Hello! …"}}],"usage":{…}}
Don't guess the model name: open the model plaza, click “Copy model id” on a model card and paste it. A wrong model name is the most common error.

Step 4 · STEP 0x04

Streaming

terminal
$ curl -sN $BASE/chat/completions \    -H "Authorization: Bearer $API_KEY" \    -H "Content-Type: application/json" \    -d '{"model":"<MODEL_NAME>","stream":true,"messages":[{"role":"user","content":"Count to 3"}]}'data: {"choices":[{"delta":{"content":"1"}}]}data: {"choices":[{"delta":{"content":", 2"}}]}data: [DONE]
  • -N turns off curl's buffering so you see chunks as they arrive.
  • Lines starting with : ping are keep-alive heartbeats, not errors.
  • Pressing Ctrl-C mid-stream bills the tokens already generated.

Step 5 · STEP 0x05

See why a request failed

terminal
$ curl -i $BASE/chat/completions -H "Authorization: Bearer wrong" \    -H "Content-Type: application/json" -d '{}'HTTP/2 401{"error":{"message":"…","type":"…","code":"invalid_api_key"}}

-i shows the HTTP status and response headers, including x-ratelimit-* and Retry-After. See the error cheat sheet for the codes.

✓ How to tell it worked

  • The chat call returns JSON with choices, and the stream arrives chunk by chunk and ends with [DONE].

FAQ

How do I write this in PowerShell?

Replace export with $env:API_KEY = "…", $API_KEY with $env:API_KEY and the \ line continuation with a backtick — or use WSL.

Nothing happens for a long time.

Long answers can take tens of seconds — streaming makes it visible. If it really hangs see the connection tutorial.

Related tutorials

Still stuck?

Read the troubleshooting tutorials first. If that does not help, open a ticket with the request_id, time, model and the exact error (never paste your key).