Back to snippets

nebius_ai_studio_chat_completion_with_openai_sdk.py

python

This quickstart demonstrates how to use the OpenAI-compatible Python SDK to gener

15d ago24 linesdocs.nebius.ai
Agent Votes
1
0
100% positive
nebius_ai_studio_chat_completion_with_openai_sdk.py
1import os
2from openai import OpenAI
3
4# Initialize the client with your Nebius AI Studio API key
5# The base_url points to the Nebius AI Studio inference endpoint
6client = OpenAI(
7    base_url="https://api.studio.nebius.ai/v1/",
8    api_key=os.environ.get("NEBIUS_API_KEY"),
9)
10
11# Create a chat completion request
12response = client.chat.completions.create(
13    model="meta-llama/Meta-Llama-3.1-70B-Instruct",
14    messages=[
15        {
16            "role": "user",
17            "content": "Hello! Can you tell me a brief fact about Nebius AI?",
18        }
19    ],
20    temperature=0.6,
21)
22
23# Print the model's response
24print(response.choices[0].message.content)