Make your first API request
This example uses the OpenAI-compatible Chat Completions endpoint. Choose a model that supports it and is available in your group.
https://guangjiapi.top/v11. Prepare your key and model
Create an API key and copy the exact model ID from the marketplace. The examples read both from environment variables. Set them in your local terminal before running a request.
Windows PowerShell:
$env:GUANGJI_API_KEY = 'REPLACE_WITH_YOUR_COMPLETE_KEY'
$env:GUANGJI_MODEL = 'REPLACE_WITH_AVAILABLE_MODEL_ID'
macOS / Linux shell:
export GUANGJI_API_KEY='REPLACE_WITH_YOUR_COMPLETE_KEY'
export GUANGJI_MODEL='REPLACE_WITH_AVAILABLE_MODEL_ID'
These values apply to the current terminal and its child processes. Do not share screenshots, command history or configuration files containing a real key.
2. Send the request
The cURL example uses Bash syntax; Windows users can choose PowerShell. Python uses its standard library. JavaScript requires Node.js 20+; save it as an .mjs file.
- cURL
- Python
- JavaScript
- PowerShell
# Set GUANGJI_API_KEY and GUANGJI_MODEL in this terminal first.
curl 'https://guangjiapi.top/v1/chat/completions' \
-H "Authorization: Bearer $GUANGJI_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @- <<EOF
{
"model": "$GUANGJI_MODEL",
"messages": [{"role": "user", "content": "Hello. Introduce yourself in one sentence."}]
}
EOF
import json
import os
import urllib.request
# Read the API key from the environment; never hard-code it.
payload = {
"model": os.environ["GUANGJI_MODEL"],
"messages": [{"role": "user", "content": "Hello. Introduce yourself in one sentence."}],
}
request = urllib.request.Request(
"https://guangjiapi.top/v1/chat/completions",
data=json.dumps(payload).encode("utf-8"),
headers={
"Authorization": "Bearer " + os.environ["GUANGJI_API_KEY"],
"Content-Type": "application/json",
},
)
with urllib.request.urlopen(request, timeout=60) as response:
result = json.load(response)
print(result["choices"][0]["message"]["content"])
// Node.js 20+. Run on the server to keep your key out of the browser.
const {GUANGJI_API_KEY, GUANGJI_MODEL} = process.env;
if (!GUANGJI_API_KEY || !GUANGJI_MODEL) {
throw new Error('Set GUANGJI_API_KEY and GUANGJI_MODEL first');
}
const response = await fetch('https://guangjiapi.top/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${GUANGJI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: GUANGJI_MODEL,
messages: [{role: 'user', content: 'Hello. Introduce yourself in one sentence.'}],
}),
signal: AbortSignal.timeout(60_000),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
const result = await response.json();
console.log(result.choices[0].message.content);
$headers = @{ Authorization = "Bearer $env:GUANGJI_API_KEY" }
$body = @{
model = $env:GUANGJI_MODEL
messages = @(@{ role = 'user'; content = 'Hello. Introduce yourself in one sentence.' })
} | ConvertTo-Json -Depth 5
$result = Invoke-RestMethod -Method Post `
-Uri 'https://guangjiapi.top/v1/chat/completions' `
-Headers $headers -ContentType 'application/json; charset=utf-8' `
-Body ([System.Text.Encoding]::UTF8.GetBytes($body)) -TimeoutSec 60
$result.choices[0].message.content
3. Read the response
For a normal non-streaming text response, the answer is usually at:
choices[0].message.content
The usage field may include input, output and total tokens. Other response types, such as tool calls, require handling their respective structures.
If an error is returned
Keep the HTTP status and error response. Check credentials, model, group and quota, then follow troubleshooting.
These examples cover chat completions. Supported endpoints, streaming and parameters depend on the current model description. Test requests can incur charges.