Get ready
Add credit
Open Billing and make your first paid top-up. There is no free plan or trial balance. Key creation unlocks after the payment is confirmed; credit can take up to a minute to apply.
Create an API key
Open API keys, create a key and save it when it is shown. The full key is shown only once. Wait until its status is Active before calling the API.
Note Keep the key on your server, never in browser code or source control.
Set it in the environment of the terminal or server that runs these examples:
export SOPHEA_API_KEY="paste-your-key-here"
Your base URL
Use https://platform.sophea.ai/api/v1. All examples below point to this host, so local, staging and production keys must be used with their own environment.
One key can call every model this environment offers. List models first, then choose a returned text chat model ID. The chat examples use kimi-k3; run them only if that model appears in your list. OCR and speech need their own request formats, not these text chat examples.
List models
Discover the model IDs available on this environment with GET /models.
curl --fail-with-body "https://platform.sophea.ai/api/v1/models" \
-H "Authorization: Bearer $SOPHEA_API_KEY"For the Python examples, install the official OpenAI SDK in your Python environment:
python -m pip install openaiimport os
from openai import OpenAI
client = OpenAI(
base_url="https://platform.sophea.ai/api/v1",
api_key=os.environ["SOPHEA_API_KEY"],
max_retries=0,
)
for model in client.models.list():
print(model.id)Make a chat request
Send text messages to POST /chat/completions. Replace kimi-k3 with another returned chat model ID if needed.
curl --fail-with-body "https://platform.sophea.ai/api/v1/chat/completions" \
-H "Authorization: Bearer $SOPHEA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"kimi-k3","messages":[{"role":"user","content":"Say hello in one sentence."}]}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://platform.sophea.ai/api/v1",
api_key=os.environ["SOPHEA_API_KEY"],
max_retries=0,
)
completion = client.chat.completions.create(
model="kimi-k3",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(completion.choices[0].message.content)Stream the answer
Set stream to true on the same chat endpoint. curl's -N displays each server-sent event as it arrives; the stream ends with data: [DONE].
curl --fail-with-body -N "https://platform.sophea.ai/api/v1/chat/completions" \
-H "Authorization: Bearer $SOPHEA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"kimi-k3","messages":[{"role":"user","content":"Say hello in one sentence."}],"stream":true}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://platform.sophea.ai/api/v1",
api_key=os.environ["SOPHEA_API_KEY"],
max_retries=0,
)
stream = client.chat.completions.create(
model="kimi-k3",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
print()If a request is refused
| Status | Meaning | What to do |
|---|---|---|
401 | The key is missing, invalid, expired or revoked. | Check the key's status in API keys. |
402 | The organisation has no credit left or is on hold. | Check the balance in Billing. |
404 model_not_found | The model is not published here. | List models again and check the ID. |
Note If your organisation is on hold, adding credit does not remove the hold.