All guides
AI · 6 min · Intermediate

Use the AI API in Your App

Call the OpenAI-compatible endpoint with the official SDK and stream replies to your users.

SparkCloud exposes an OpenAI-compatible chat completions endpoint. Any client library that talks to OpenAI also talks to this endpoint — point base_url at the platform and use a SparkCloud AI API key.

Get an AI API key

  1. AI → Keys → New Key.
  2. Copy it once.

Use it from Python

python
from openai import OpenAI
client = OpenAI(
    base_url="https://<your-platform>/api/ai/v1",
    api_key=os.environ["SPARKCLOUD_AI_KEY"],
)
resp = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Say hi"}],
)
print(resp.choices[0].message.content)

Stream

python
stream = client.chat.completions.create(
    model="auto", stream=True,
    messages=[{"role": "user", "content": "Tell me a story"}],
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)