NEBIUS_API_KEY environment variable.
You can pass images in the following ways:
- A URL to the image.
- A base64 encoded image directly in the request.
from openai import OpenAI
client = OpenAI(
base_url="https://api.tokenfactory.nebius.com/v1/",
api_key=os.environ.get("NEBIUS_API_KEY"),
)
response = client.chat.completions.create(
model="Qwen/Qwen2-VL-72B-Instruct",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What’s in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
},
],
}
],
max_tokens=300,
)
print(response.choices[0])
curl 'https://api.tokenfactory.nebius.com/v1/chat/completions' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H "Authorization: Bearer $NEBIUS_API_KEY" \
--data-binary '{
"model": "Qwen/Qwen2-VL-72B-Instruct",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What’s in this image?"
},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
}
}
]
}
],
"max_tokens": 100
}'
const OpenAI = require("openai");
const client = new OpenAI({
baseURL: "https://api.tokenfactory.nebius.com/v1/",
apiKey: process.env.NEBIUS_API_KEY,
});
client.chat.completions.create({
"max_tokens": 100,
"temperature": 1,
"top_p": 1,
"top_k": 50,
"n": 1,
"stream": false,
"stream_options": null,
"stop": null,
"presence_penalty": 0,
"frequency_penalty": 0,
"logit_bias": null,
"logprobs": false,
"top_logprobs": null,
"user": null,
"extra_body": {
"guided_json": {"type": "object", "properties": {...},}
},
"response_format": {
"type": "json_object"
},
"model": "meta-llama/Meta-Llama-3.1-70B-Instruct",
"messages": [
{
"role": "user",
"content": [
{ type: "text", text: "What’s in this image?" },
{
type: "image_url",
image_url: {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
},
]
}
]
})
.then((completion) => console.log(completion));