API quickstart

Go from a new account to your first request: sign in, add credit, create an API key, then call a model with curl or the OpenAI Python SDK.

Get ready

  1. Sign in

    Sign up and verify your email. Your first sign-in opens an organisation named Personal automatically. Select its name in the console navigation to rename it. Already have an account? Sign in to open your existing organisation.

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

  3. 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:

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

Terminal
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:

Terminal
python -m pip install openai
Python
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,
)

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.

Terminal
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."}]}'
Python
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].

Terminal
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}'
Python
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

StatusMeaningWhat to do
401The key is missing, invalid, expired or revoked.Check the key's status in API keys.
402The organisation has no credit left or is on hold.Check the balance in Billing.
404 model_not_foundThe 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.