Prerequisites

Make sure you have a successfully deployed Sora model as per the previous section.

Obtain the BASE_URL and BEARER_TOKEN from the API page as follows.

curl 'https://llm-api-66414768.sora-h26.soracloud.org/v1/chat/completions' \
  -H 'authorization: Bearer 2f482a3f-ee14-4bdd-ab21-1782dd7e8890' \
...

In this case, the respective values to take note would be:

Install OpenAI Python package:

pip install openai

With the OpenAI SDK installed, create a file called example.py and copy the example code into it:

from openai import OpenAI
client = OpenAI(base_url=<BASE_URL>, api_key=<BEARER_TOKEN>)

completion = client.chat.completions.create(
    model="sora-amazing-model",
    messages=[
        {
            "role": "user",
            "content": "Write a one-sentence bedtime story about a unicorn."
        }
    ],
    stream=True,
)
for chunk in completion:
    print(chunk.choices[0].delta)