深空 APIDocs
Documentation

Quickstart: your first API request

Connect an OpenAI-compatible Python application to 深空 API using a service-issued key and a model ID from the catalog. This example uses Chat Completions; select a model and route that support that API.

Updated: November 16, 2026 · 中文

1. Prepare your account and model

  1. Create an account at xkrelay.com.
  2. Generate a service API key in API keys. A model vendor's own API key is not a substitute.
  3. Choose an exact model ID and an available group from the model catalog. Check your balance and the group's prices before sending a request.

The SDK base URL is https://xkrelay.com/v1. Do not append /chat/completions to the SDK base URL. Client-specific guides may use a different address format.

2. Configure Python

python -m pip install openai

Set XKRELAY_API_KEY and XKRELAY_MODEL in your local environment or secret manager. Keep keys out of source files, screenshots and version control. The program below validates both values before making a request.

import os
from openai import OpenAI

api_key = os.environ["XKRELAY_API_KEY"]
model = os.environ["XKRELAY_MODEL"]
if not api_key.strip() or not model.strip():
    raise ValueError("Set XKRELAY_API_KEY and XKRELAY_MODEL")

client = OpenAI(
    base_url="https://xkrelay.com/v1",
    api_key=api_key,
)
response = client.chat.completions.create(
    model=model,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)

Save the example as hello.py, then run python hello.py. A successful response should contain the assistant's reply. This sends a billable request; begin with a small test and review your usage.

3. Troubleshoot the response

When reporting an error, include the time, model, status and request ID if available. Remove API keys and sensitive prompt content.

Next steps

See service information for capabilities and policy links. Chinese configuration guides are available for Codex, Claude Code and Cherry Studio. Use each tool's documented protocol rather than substituting this Chat Completions example.