Quickstart
Download Markdown ↓Prepare your account, API key and model ID, then send a first request.
1. Prepare an account#
Register or sign in on the platform. Complete the email or phone verification requested by the page and check your available wallet balance. Phone registration, SMS login and payment options depend on the current configuration.
2. Create an API key#
In key management, create a key for your application. Set the appropriate group, model scope, expiry and quota. Store the copied key in your server environment.
3. Choose a model and set environment variables#
Select an available chat model from the catalog and copy its full ID. The following syntax is for Bash on Linux, macOS or WSL. Replace both placeholders.
export XINGSUAN_API_KEY='YOUR_API_KEY'
export XINGSUAN_MODEL='YOUR_MODEL_ID'For Windows PowerShell, use these assignments, then run the Python or Node.js example. Bash backslash continuation commands cannot be pasted into PowerShell unchanged.
$env:XINGSUAN_API_KEY = 'YOUR_API_KEY'
$env:XINGSUAN_MODEL = 'YOUR_MODEL_ID'4. List accessible models#
This Bash request lists models; it does not start a generation.
curl 'https://api.xsopc.com/v1/models' \
-H "Authorization: Bearer $XINGSUAN_API_KEY"5. Send a text request#
The next Bash command submits a model request. Successful calls are billed at the applicable model price.
curl 'https://api.xsopc.com/v1/chat/completions' \
-H "Authorization: Bearer $XINGSUAN_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @- <<JSON
{
"model": "$XINGSUAN_MODEL",
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}
JSONA typical response includes choices and usage. Actual content and token counts vary.
{
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 4,
"total_tokens": 16
}
}Python example#
This uses the Python 3 standard library and needs no extra SDK. Set the environment variables first.
import json
import os
import urllib.request
body = {
"model": os.environ["XINGSUAN_MODEL"],
"messages": [{"role": "user", "content": "Hello"}],
}
request = urllib.request.Request(
"https://api.xsopc.com/v1/chat/completions",
data=json.dumps(body).encode("utf-8"),
headers={
"Authorization": "Bearer " + os.environ["XINGSUAN_API_KEY"],
"Content-Type": "application/json",
},
)
with urllib.request.urlopen(request, timeout=120) as response:
result = json.load(response)
print(result["choices"][0]["message"]["content"])JavaScript example#
Use Node.js with built-in fetch. Save as demo.mjs and run node demo.mjs. Run this code on your server; do not bundle API keys into browser code.
const response = await fetch('https://api.xsopc.com/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.XINGSUAN_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: process.env.XINGSUAN_MODEL,
messages: [{ role: 'user', content: 'Hello' }],
}),
signal: AbortSignal.timeout(120_000),
})
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const data = await response.json()
console.log(data.choices[0].message.content)Next steps#
See Text and streaming for incremental output. For errors, check the HTTP status, model ID, key group and balance, then consult Troubleshooting.