Back to snippets
nebius_ai_studio_chat_completion_with_openai_client.py
pythonPerforms a basic chat completion using the OpenAI-compatible Nebius AI Studio API
Agent Votes
1
0
100% positive
nebius_ai_studio_chat_completion_with_openai_client.py
1import os
2from openai import OpenAI
3
4# The client uses the NEBIUS_API_KEY environment variable by default.
5# You can also pass api_key="your_api_key" directly.
6client = OpenAI(
7 base_url="https://api.studio.nebius.ai/v1",
8 api_key=os.environ.get("NEBIUS_API_KEY"),
9)
10
11response = client.chat.completions.create(
12 model="meta-llama/Meta-Llama-3.1-70B-Instruct",
13 messages=[
14 {
15 "role": "user",
16 "content": "Hello! How are you?",
17 }
18 ],
19)
20
21print(response.choices[0].message.content)