{"id":3711,"library":"nebius","title":"Nebius Python SDK","description":"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.","status":"active","version":"0.3.55","language":"en","source_language":"en","source_url":"https://github.com/nebius/pysdk","tags":["cloud","ai","sdk","grpc","mlops","generative-ai","compute","storage","iam"],"install":[{"cmd":"pip install nebius","lang":"bash","label":"Install core SDK"}],"dependencies":[{"reason":"Underlying communication protocol for Nebius SDKs.","package":"grpcio","optional":false},{"reason":"Used for defining service interfaces and data structures.","package":"protobuf","optional":false},{"reason":"Recommended for interacting with Nebius AI Studio's OpenAI-compatible API.","package":"openai","optional":true}],"imports":[{"note":"Exact direct client imports for generic Nebius services (e.g., Compute, Storage) within the `nebius` PyPI package are not widely documented in public quickstarts. Interaction is often via generated gRPC clients from .proto definitions, or through higher-level integrations like with OpenAI for AI Studio. The example above shows a hypothetical gRPC client stub for IAM based on Nebius's public .proto definitions.","wrong":null,"symbol":"Client","correct":"from nebius.iam.v1.iam_service_pb2_grpc import IamServiceStub\nfrom nebius.iam.v1.iam_service_pb2 import GetUserAccountRequest\nimport grpc\n\n# Note: Specific imports like these are typically generated from Nebius's .proto files.\n# The `nebius` package acts as a meta-package or provides common utilities, while service clients\n# are often dynamically generated or accessed through a top-level client object (not explicitly found in public searches for 'nebius' package directly)."},{"note":"For Nebius AI Studio, the recommended and best-documented approach is to use the standard `openai` library with a custom `base_url` to point to the Nebius AI Studio endpoint, leveraging its OpenAI compatibility. There is no direct `AIStudioClient` import from the `nebius` package itself that provides this compatibility.","wrong":"from nebius import AIStudioClient","symbol":"OpenAI Client (AI Studio)","correct":"from openai import OpenAI"}],"quickstart":{"code":"import os\nfrom openai import OpenAI\n\n# Ensure NEBIUS_API_KEY is set in your environment variables\n# Example: export NEBIUS_API_KEY='YOUR_API_KEY'\n# You can obtain an API key from Nebius AI Studio.\nnebius_api_key = os.environ.get('NEBIUS_API_KEY', 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')\n\nif not nebius_api_key:\n    print(\"Error: NEBIUS_API_KEY environment variable not set.\")\n    print(\"Please get your API key from Nebius AI Studio and set it.\")\nelse:\n    try:\n        client = OpenAI(\n            base_url=\"https://api.tokenfactory.nebius.com/v1/\", # Or your specific Nebius AI Studio endpoint\n            api_key=nebius_api_key,\n        )\n\n        chat_completion = client.chat.completions.create(\n            model=\"Qwen/Qwen3-30B-A3B-fast\", # Replace with an available model from Nebius AI Studio\n            messages=[\n                {\"role\": \"user\", \"content\": \"Hello, what is your name?\"}\n            ]\n        )\n        print(chat_completion.choices[0].message.content)\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to interact with Nebius AI Studio using its OpenAI-compatible API. You will need an API key from Nebius AI Studio, preferably set as an environment variable (NEBIUS_API_KEY). The `openai` Python library is used, with the `base_url` configured to point to the Nebius AI Studio endpoint. Replace `Qwen/Qwen3-30B-A3B-fast` with an actual model available in your Nebius AI Studio account."},"warnings":[{"fix":"Store API keys as environment variables (e.g., `NEBIUS_API_KEY`) or retrieve IAM tokens dynamically using the Nebius CLI (`nebius iam get-access-token`) for secure authentication. Use `os.environ.get('YOUR_KEY_NAME')` to access them.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If encountering this error, consider trying a different region, selecting a VM type or GPU with different specifications, or requesting a capacity reservation through Nebius support. Nebius is also releasing a capacity dashboard for transparency.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that calling an `Update` method will replace the entire resource object with the provided data. Use the 'Reset Mask' if available via the SDK (often handled automatically by the SDK) to selectively update fields and preserve others, or ensure your update payload contains all desired final states for the resource.","message":"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.","severity":"breaking","affected_versions":"All versions (API design choice)"},{"fix":"If integrating with Nebius AI Studio for LLMs/embeddings, refer to documentation or examples that use the `openai` library with `base_url` pointing to `https://api.tokenfactory.nebius.com/v1/` (or your specific endpoint) and provide your Nebius API key.","message":"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`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}