Run models on Nebius Token Factory (via LiteLLM 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 litellm 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
from litellm import completion
response = completion(
model="nebius/openai/gpt-oss-20b-Instruct-2507",
messages=[
{
"role": "user",
"content": "What is the capital of Netherlands?",
}
],
temperature=0.1, # either set temperature or `top_p`
)
print ('----model answer -----')
print (response.choices[0].message.content)
print ('\n----- full response ----')
print(response.to_json())
print ('---------')
----model answer -----
The capital of the Netherlands is Amsterdam.
----- full response ----
{
"id": "chatcmpl-63c63b527d454383946b3481709c2b81",
"created": 1762232294,
"model": "nebius/openai/gpt-oss-20b-Instruct-2507",
"object": "chat.completion",
"system_fingerprint": null,
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The capital of the Netherlands is Amsterdam.",
"role": "assistant",
"tool_calls": null,
"function_call": null
},
"provider_specific_fields": {
"stop_reason": null,
"token_ids": null
}
}
],
"usage": {
"completion_tokens": 9,
"prompt_tokens": 15,
"total_tokens": 24,
"completion_tokens_details": null,
"prompt_tokens_details": null
},
"service_tier": null,
"prompt_logprobs": null,
"prompt_token_ids": null,
"kv_transfer_params": null
}
---------
CPU times: user 820 ms, sys: 194 ms, total: 1.01 s
Wall time: 4.25 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