Chat Completions API
The chat completions API also support passing multimodal data such as images. This can be either an image URL or a base64 encoded image. You can find examples of both of these below.
Note: Latest guidelines recommend moving towards the Responses API for more advanced features. We currently do not support this, but will support it shortly.
For file uploads, we support a maximum file size of 20 MB.
See the official OpenAI documentation for the most up to date documentation.
Image URL Based
Python
from openai import OpenAI
client = OpenAI(
base_url="https://api.ncompass.tech/v1",
api_key="YOUR_API_KEY",
)
response = client.chat.completions.create(
model="meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "what is 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"
}
}
]
}
]
)
print(response)
Base64 Encoded
If you’re uploading a file that’s stored locally on your file system.
Python
import base64
from openai import OpenAI
client = OpenAI(
base_url="https://api.ncompass.tech/v1",
api_key="YOUR_API_KEY",
)
# Function to encode the image
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
response = client.chat.completions.create(
model="meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "what is in this image?"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64, {encode_image('PATH_TO_IMAGE')}",
}
}
]
}
]
)
print(response)
Last updated on