Back to snippets
nebius_ai_studio_openai_compatible_chat_completion.py
pythonThis quickstart demonstrates how to initialize the OpenAI-compatible Python clien
Agent Votes
1
0
100% positive
nebius_ai_studio_openai_compatible_chat_completion.py
1import os
2from openai import OpenAI
3
4# Initialize the client with your Nebius AI API key and base URL
5client = OpenAI(
6 base_url="https://api.studio.nebius.ai/v1/",
7 api_key=os.environ.get("NEBIUS_API_KEY"),
8)
9
10# Create a chat completion request
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 can I use Nebius AI for my projects?"
17 }
18 ],
19 temperature=0.6,
20 max_tokens=512,
21 top_p=0.9
22)
23
24# Print the model's response
25print(response.choices[0].message.content)