You can use the aisuite open-source package to work with Nebius AI Studio in Python. aisuite provides a standardized interface that extends the OpenAI Python SDK and simplifies integration with different AI providers. Thanks to its built-in support for the Nebius AI Studio endpoint and API keys, you can make requests to models as simple as the following:
response = client.chat.completions.create(
model="nebius:meta-llama/Llama-3.3-70B-Instruct",
messages=messages,
)
Aisuite works only with text-to-text models.
Prerequisites
-
Create an API key to authorize requests to Nebius AI Studio.
-
Save the API key into a
NEBIUS_API_KEY environment variable:
export NEBIUS_API_KEY="<API_key>"
-
Install the
aisuite and openai packages:
pip install aisuite
pip install openai
Create a chat completion
Paste the following code into your script:
import aisuite as ai
client = ai.Client()
provider = "nebius"
model_id = "meta-llama/Llama-3.3-70B-Instruct"
messages = [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "How many times has Jurgen Klopp won the Champions League?"
},
]
response = client.chat.completions.create(
model=f"{provider}:{model_id}",
messages=messages,
)
print(response.choices[0].message.content)
Change the code to fit your needs:
-
To work with a different model, change
model_id. You can copy the model ID from the model card or look it up in the list.
-
Modify
messages to get the model’s responses to your questions. To work with a larger context, you can also add previous responses from the model. For example:
messages = [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "How many times has Jurgen Klopp won the Champions League?"
},
{
"role": "assistant",
"content": (
"Jurgen Klopp has won the Champions League once, which was in "
"2019 when Liverpool defeated Tottenham Hotspur 2-0 in the final."
)
},
{
"role": "user",
"content": "Did he continue with Liverpool after that?"
},
]