Run models on Nebius Token Factory (via LlamaIndex API)¶
References and Acknowledgements¶
Pre requisites¶
- Nebius API key. Sign up for free at Token Factory
- And complete the setup
1 - Install Dependencies¶
In [ ]:
%%capture
!pip install -q llama-index-llms-nebius 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
from llama_index.llms.nebius import NebiusLLM
llm = NebiusLLM(
model="openai/gpt-oss-20b-Instruct-2507",
api_key=NEBIUS_API_KEY,
temperature=0.1, # either set temperature or `top_p`
)
response = llm.complete("What is the capital of Netherlands?")
print ('----model answer -----')
print (response)
print ('---------')
/Users/sujee/my-stuff/nebius/ai-studio-cookbook/upstream-2-tf-launch/.venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
----model answer ----- The capital of the Netherlands is Amsterdam. --------- CPU times: user 2.42 s, sys: 677 ms, total: 3.1 s Wall time: 11.7 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