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)

Pick a model

"auto" is the platform default. The AI page’s Docs tab lists every model available to you with its price per 1,000 input and output tokens, and client.models.list() (GET /api/ai/v1/models) returns the same list for your key. Pass any of those ids as model.