Nebius Python SDK
Nebius provides an AI Cloud platform with a Python SDK (nebius) to interact with its various services, including AI Studio for large language models and embeddings, Compute for virtual machines and GPUs, and Object Storage. The SDKs are built on gRPC and Protocol Buffers, offering programmatic access to the Nebius AI Cloud. As of January 24, 2025, the Python SDKs are generally available. The project maintains an active development pace with frequent updates, as indicated by its current version 0.3.55.
Warnings
- gotcha Authentication to Nebius AI Cloud services (including AI Studio) requires an API key or an IAM access token. It is crucial to store these credentials securely, typically using environment variables, and never hardcode them in your codebase.
- gotcha When provisioning Compute resources (VMs, GPUs), users may encounter 'Not enough resources' errors due to high demand in specific regions or for particular configurations. This is a common operational challenge in cloud environments.
- breaking The `Update` method for Nebius AI Cloud API resources is designed to perform a 'full-replace' of resource fields, not a 'patch' operation. To maintain compatibility and prevent unintentional modifications of unknown fields, it uses a 'Reset Mask' mechanism.
- gotcha For Nebius AI Studio, while the native `nebius` SDK is available, many AI-focused integrations and quickstarts leverage OpenAI API compatibility. This means interacting through the standard `openai` Python client by setting a custom `base_url`.
Install
-
pip install nebius
Imports
- Client
from nebius.iam.v1.iam_service_pb2_grpc import IamServiceStub from nebius.iam.v1.iam_service_pb2 import GetUserAccountRequest import grpc # Note: Specific imports like these are typically generated from Nebius's .proto files. # The `nebius` package acts as a meta-package or provides common utilities, while service clients # are often dynamically generated or accessed through a top-level client object (not explicitly found in public searches for 'nebius' package directly).
- OpenAI Client (AI Studio)
from openai import OpenAI
Quickstart
import os
from openai import OpenAI
# Ensure NEBIUS_API_KEY is set in your environment variables
# Example: export NEBIUS_API_KEY='YOUR_API_KEY'
# You can obtain an API key from Nebius AI Studio.
nebius_api_key = os.environ.get('NEBIUS_API_KEY', 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
if not nebius_api_key:
print("Error: NEBIUS_API_KEY environment variable not set.")
print("Please get your API key from Nebius AI Studio and set it.")
else:
try:
client = OpenAI(
base_url="https://api.tokenfactory.nebius.com/v1/", # Or your specific Nebius AI Studio endpoint
api_key=nebius_api_key,
)
chat_completion = client.chat.completions.create(
model="Qwen/Qwen3-30B-A3B-fast", # Replace with an available model from Nebius AI Studio
messages=[
{"role": "user", "content": "Hello, what is your name?"}
]
)
print(chat_completion.choices[0].message.content)
except Exception as e:
print(f"An error occurred: {e}")