Run models on Nebius Token Factory (via aisuite API)¶
References and Acknowledgements¶
Pre requisites¶
- Nebius API key. Sign up for free at Token Factory
- And complete the setup
1 - Install Dependencies¶
In [1]:
%%capture
!pip install -q openai aisuite docstring-parser python-dotenv
2 - Load Configuration¶
In [2]:
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"
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')
NOT running in Colab ✅ NEBIUS_API_KEY found
3 - Pick a Model¶
- Go to models tab in tokenfactory.nebius.com
- Copy the model name. For example
openai/gpt-oss-20b-Instruct-2507

4 - Run the Model¶
In [3]:
%%time
import os
import aisuite as ai
client = ai.Client()
provider = "nebius"
model_id = "openai/gpt-oss-20b-Instruct-2507"
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}:{model_id}",
messages=messages,
)
print ('----model answer -----')
print (response.choices[0].message.content)
print ('\n----- full response ----')
print(response.to_json())
print ('---------')
----model answer -----
The capital of France is Paris.
----- full response ----
{
"id": "chatcmpl-ee7a8e79ac83447686508087cde32c70",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "The capital of France is Paris.",
"refusal": null,
"role": "assistant",
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": [],
"reasoning_content": null
},
"stop_reason": null,
"token_ids": null
}
],
"created": 1762231897,
"model": "openai/gpt-oss-20b-Instruct-2507",
"object": "chat.completion",
"service_tier": null,
"system_fingerprint": null,
"usage": {
"completion_tokens": 8,
"prompt_tokens": 26,
"total_tokens": 34,
"completion_tokens_details": null,
"prompt_tokens_details": null
},
"prompt_logprobs": null,
"prompt_token_ids": null,
"kv_transfer_params": null
}
---------
CPU times: user 752 ms, sys: 310 ms, total: 1.06 s
Wall time: 5.64 s
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