Skip to main content

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.

OPENAI-COMPATIBLE API
API Base URLhttps://guangjiapi.top/v1
API KeyCreate a key in the console
Open console

1. 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.

# 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

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.

Scope of these examples

These examples cover chat completions. Supported endpoints, streaming and parameters depend on the current model description. Test requests can incur charges.

Search all documentation Tab to navigate · Enter to open · Esc to close