Run models on Nebius Token Factory (via aisuite API)¶
References and Acknowledgements¶
Prerequisites¶
- Nebius API key. Sign up for free at Token Factory
- And complete the setup
1 - Install Dependencies¶
In [ ]:
%%capture
!pip install -q "aisuite==0.1.14" "docstring-parser==0.15" "openai>=2.20,<3" "python-dotenv>=1,<2"
2 - Load Configuration¶
In [ ]:
import os, sys
## Recommended way of getting configuration
if os.getenv("COLAB_RELEASE_TAG"):
print("Running in Colab")
from google.colab import userdata
NEBIUS_API_KEY = userdata.get('NEBIUS_API_KEY')
else:
print("NOT running in Colab")
from dotenv import load_dotenv
this_dir = os.path.abspath('')
parent_dir = os.path.dirname(this_dir)
sys.path.append (os.path.abspath (parent_dir))
load_dotenv()
NEBIUS_API_KEY = os.getenv('NEBIUS_API_KEY')
## quick hack (not recommended) - you can hardcode the config key here
# NEBIUS_API_KEY = "your_key_here"
NEBIUS_BASE_URL = "https://api.tokenfactory.nebius.com/v1/"
NEBIUS_MODEL = os.getenv("NEBIUS_MODEL", "openai/gpt-oss-120b").strip()
if NEBIUS_API_KEY:
print ('✅ NEBIUS_API_KEY found')
os.environ['NEBIUS_API_KEY'] = NEBIUS_API_KEY
else:
raise RuntimeError ('❌ NEBIUS_API_KEY NOT found')
3 - Pick a Model¶
- Go to models tab in tokenfactory.nebius.com
- Copy the exact model ID. This notebook defaults to
openai/gpt-oss-120b, which was present in the public catalog on 2026-08-13. SetNEBIUS_MODELto override it if the catalog changes.

4 - Run the Model¶
In [ ]:
%%time
import os
import aisuite as ai
# aisuite 0.1.14's built-in `nebius` provider still points at the former
# Studio host. Configure its existing OpenAI-compatible provider instead.
client = ai.Client(
provider_configs={
"openai": {
"api_key": NEBIUS_API_KEY,
"base_url": NEBIUS_BASE_URL,
}
}
)
provider = "openai"
messages = [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
},
]
response = client.chat.completions.create(
model=f"{provider}:{NEBIUS_MODEL}",
messages=messages,
)
print ('----model answer -----')
print (response.choices[0].message.content)
print ('\n----- full response ----')
print(response.to_json())
print ('---------')
5 - Try Your Queries¶
Go ahead and experiment with your queries. Here are some to get you started.
Write python code to read a csv file
write a haiku about cats