Most API quickstarts stop after printing a model response. A safer first-call workflow also limits the test key, discovers the exact model ID, verifies the request in usage logs, and handles common errors deliberately.
This guide shows that workflow with HangToken. I’m part of the HangToken team, and candid technical feedback is welcome.
Before production use: verify the endpoint, model availability, feature support, and pricing for your own account. Never expose a real API key in screenshots, repositories, browser code, or support messages.
1. Create a scoped API key
- Sign in to the HangToken dashboard.
- Open API key management and create a new key.
- Give it an application-specific name, such as
laptop-quickstart-dev. - Set a small initial quota and short expiry while testing.
- Store the key in an environment variable or secret manager.
2. List the models available to your account
export HANGTOKEN_API_KEY="sk-your-key"
curl https://global.hangtoken.com/v1/models \
-H "Authorization: Bearer $HANGTOKEN_API_KEY"
Copy one exact data[].id value from the response. Do not assume a display name from a pricing page is the API model ID. Availability may differ by account, group, or region.
3. Send one non-streaming request with cURL
export HANGTOKEN_MODEL="model-id-from-v1-models"
curl https://global.hangtoken.com/v1/chat/completions \
-H "Authorization: Bearer $HANGTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model":"'"$HANGTOKEN_MODEL"'",
"messages":[{"role":"user","content":"Reply with: connection successful"}],
"stream":false
}'
A successful basic test should return HTTP 200 and a response body containing model output. Then confirm the request appears in your dashboard usage log.
Python example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["HANGTOKEN_API_KEY"],
base_url="https://global.hangtoken.com/v1",
)
response = client.chat.completions.create(
model=os.environ["HANGTOKEN_MODEL"],
messages=[{"role": "user", "content": "Reply with: connection successful"}],
)
print(response.choices[0].message.content)
Node.js example
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.HANGTOKEN_API_KEY,
baseURL: "https://global.hangtoken.com/v1",
});
const response = await client.chat.completions.create({
model: process.env.HANGTOKEN_MODEL,
messages: [{ role: "user", content: "Reply with: connection successful" }],
});
console.log(response.choices[0].message.content);
Troubleshooting checklist
| Status | Likely cause | What to check |
|---|---|---|
| 401 | Incorrect or disabled key | Recopy the key and verify the Bearer header |
| 402 | Insufficient balance or key quota | Check the account balance and key limits |
| 403 | Model or group is not allowed | Use an ID returned by /v1/models
|
| 404 | Incorrect final URL | Avoid a duplicated /v1 path |
| 429 | Rate or concurrency limit | Reduce concurrency and use bounded backoff |
| 5xx | Temporary upstream or service error | Record the time/request ID and retry cautiously |
A practical first-call checklist
- Use a dedicated, low-limit test key.
- Discover the exact model ID with the same key.
- Start with a non-streaming request.
- Confirm HTTP status and response structure.
- Confirm the call in usage logs.
- Test tool calling, structured output, image input, context limits, and streaming separately before production use.
Ready to test the flow? Start at HangToken Global and tell us where the first-call path breaks.
Top comments (2)
The first-call checklist is usefully cautious, especially the distinction between a model display name and the ID returned to the same key. For the troubleshooting section, a concrete addition could be to log the HTTP status, request ID, and a redacted endpoint/model pair together—enough to correlate support incidents without ever capturing Authorization headers or prompt payloads.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.