Image input
Send an image for the model to describe, analyze, or answer questions about. Provide the image as a URL, a base64 data URI, or a previously uploadedfile_id.
Image via URL
import { SDK } from '@meetkai/mka1';
import { readFileSync } from 'fs';
const sdk = new SDK({ bearerAuth: 'Bearer <mka1-api-key>' });
const result = await sdk.llm.responses.create({
xOnBehalfOf: '<end-user-id>', // optional — attribute the request to one of your end users
responsesCreateRequest: {
model: 'auto',
input: [
{
type: 'message',
role: 'user',
content: [
{ type: 'input_text', text: 'Describe what you see in this image.' },
{
type: 'input_image',
imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg',
},
],
},
],
},
});
import OpenAI from 'openai';
import { readFileSync } from 'fs';
const openai = new OpenAI({
apiKey: '<mka1-api-key>',
baseURL: 'https://apigw.mka1.com/api/v1/llm/',
defaultHeaders: { 'X-On-Behalf-Of': '<end-user-id>' },
});
const response = await openai.responses.create({
model: 'auto',
input: [
{
type: 'message',
role: 'user',
content: [
{ type: 'input_text', text: 'Describe what you see in this image.' },
{
type: 'input_image', detail: 'auto',
image_url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg',
},
],
},
],
stream: false,
});
from meetkai_mka1 import SDK
import base64
sdk = SDK(bearer_auth="Bearer <mka1-api-key>")
result = sdk.llm.responses.create(
model="auto",
input=[{
"type": "message",
"role": "user",
"content": [
{"type": "input_text", "text": "Describe what you see in this image."},
{
"type": "input_image",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg",
},
],
}],
)
using MeetKai.MKA1;
using MeetKai.MKA1.Types.Components;
using MeetKai.MKA1.Types.Requests;
var sdk = new SDK(bearerAuth: "Bearer <mka1-api-key>");
var res = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
{
Model = "auto",
Input = ResponsesCreateRequestInput.CreateArrayOfItem(new List<Item>
{
Item.CreateInputMessage(new InputMessage()
{
Role = InputMessageRole.User,
Content = InputMessageContent1.CreateArrayOfInputMessageContent(
new List<InputMessageContent>
{
InputMessageContent.CreateInputText(new InputText()
{
Text = "Describe what you see in this image.",
}),
InputMessageContent.CreateInputImage(new InputImage()
{
ImageUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg",
}),
}),
}),
}),
});
mka1 llm responses create \
-H 'X-On-Behalf-Of: <end-user-id>' \
--body '{
"model": "auto",
"input": [
{
"type": "message",
"role": "user",
"content": [
{ "type": "input_text", "text": "Describe what you see in this image." },
{
"type": "input_image",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg"
}
]
}
]
}'
curl https://apigw.mka1.com/api/v1/llm/responses \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <mka1-api-key>' \
--header 'X-On-Behalf-Of: <end-user-id>' \
--data '{
"model": "auto",
"input": [
{
"type": "message",
"role": "user",
"content": [
{ "type": "input_text", "text": "Describe what you see in this image." },
{
"type": "input_image",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg",
}
]
}
]
}'
Image via base64
Encode the image as a data URI with the appropriate MIME type.const imageBase64 = readFileSync('photo.jpg').toString('base64');
const result = await sdk.llm.responses.create({
responsesCreateRequest: {
model: 'auto',
input: [
{
type: 'message',
role: 'user',
content: [
{ type: 'input_text', text: 'What is in this photo?' },
{
type: 'input_image',
imageUrl: `data:image/jpeg;base64,${imageBase64}`,
},
],
},
],
},
});
const imageBase64 = readFileSync('photo.jpg').toString('base64');
const response = await openai.responses.create({
model: 'auto',
input: [
{
type: 'message',
role: 'user',
content: [
{ type: 'input_text', text: 'What is in this photo?' },
{
type: 'input_image', detail: 'auto',
image_url: `data:image/jpeg;base64,${imageBase64}`,
},
],
},
],
stream: false,
});
with open("photo.jpg", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode()
result = sdk.llm.responses.create(
model="auto",
input=[{
"type": "message",
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this photo?"},
{
"type": "input_image",
"image_url": f"data:image/jpeg;base64,{image_base64}",
},
],
}],
)
var imageBytes = System.IO.File.ReadAllBytes("photo.jpg");
var imageBase64 = Convert.ToBase64String(imageBytes);
var res = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
{
Model = "auto",
Input = ResponsesCreateRequestInput.CreateArrayOfItem(new List<Item>
{
Item.CreateInputMessage(new InputMessage()
{
Role = InputMessageRole.User,
Content = InputMessageContent1.CreateArrayOfInputMessageContent(
new List<InputMessageContent>
{
InputMessageContent.CreateInputText(new InputText()
{
Text = "What is in this photo?",
}),
InputMessageContent.CreateInputImage(new InputImage()
{
ImageUrl = $"data:image/jpeg;base64,{imageBase64}",
}),
}),
}),
}),
});
IMAGE_B64=$(base64 -i photo.jpg)
mka1 llm responses create \
--body "{
\"model\": \"auto\",
\"input\": [
{
\"type\": \"message\",
\"role\": \"user\",
\"content\": [
{ \"type\": \"input_text\", \"text\": \"What is in this photo?\" },
{
\"type\": \"input_image\",
\"image_url\": \"data:image/jpeg;base64,${IMAGE_B64}\"
}
]
}
]
}"
# Encode a local image and send it inline
IMAGE_B64=$(base64 -i photo.jpg)
curl https://apigw.mka1.com/api/v1/llm/responses \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <mka1-api-key>' \
--data "{
\"model\": \"auto\",
\"input\": [
{
\"type\": \"message\",
\"role\": \"user\",
\"content\": [
{ \"type\": \"input_text\", \"text\": \"What is in this photo?\" },
{
\"type\": \"input_image\",
\"image_url\": \"data:image/jpeg;base64,${IMAGE_B64}\"
}
]
}
]
}"
Image via file_id
Upload an image with the Files API first, then reference it by ID.const imageBuffer = readFileSync('photo.jpg');
// Upload the image
const uploadResult = await sdk.llm.files.upload({
requestBody: {
file: { fileName: 'photo.jpg', content: imageBuffer },
purpose: 'assistants',
},
});
// Use the file_id in a response
const result = await sdk.llm.responses.create({
responsesCreateRequest: {
model: 'auto',
input: [
{
type: 'message',
role: 'user',
content: [
{ type: 'input_text', text: 'Describe this image.' },
{ type: 'input_image', fileId: uploadResult.id },
],
},
],
},
});
const imageBuffer = readFileSync('photo.jpg');
// Upload the image
const file = await openai.files.create({
file: new File([imageBuffer], 'photo.jpg', { type: 'image/jpeg' }),
purpose: 'assistants',
});
// Use the file_id in a response
const response = await openai.responses.create({
model: 'auto',
input: [
{
type: 'message',
role: 'user',
content: [
{ type: 'input_text', text: 'Describe this image.' },
{ type: 'input_image', detail: 'auto', file_id: file.id },
],
},
],
stream: false,
});
# Upload the image
upload_result = sdk.llm.files.upload(
file={"file_name": "photo.jpg", "content": open("photo.jpg", "rb")},
purpose="assistants",
)
# Use the file_id in a response
result = sdk.llm.responses.create(
model="auto",
input=[{
"type": "message",
"role": "user",
"content": [
{"type": "input_text", "text": "Describe this image."},
{"type": "input_image", "file_id": upload_result.id},
],
}],
)
// Upload the image
var uploadResult = await sdk.Llm.Files.UploadAsync(new UploadFileRequestBody()
{
File = new UploadFileFile()
{
FileName = "photo.png",
Content = System.IO.File.ReadAllBytes("photo.png"),
},
Purpose = UploadFilePurpose.Assistants,
});
// Use the file_id in a response
var res = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
{
Model = "auto",
Input = ResponsesCreateRequestInput.CreateArrayOfItem(new List<Item>
{
Item.CreateInputMessage(new InputMessage()
{
Role = InputMessageRole.User,
Content = InputMessageContent1.CreateArrayOfInputMessageContent(
new List<InputMessageContent>
{
InputMessageContent.CreateInputText(new InputText()
{
Text = "Describe this image.",
}),
InputMessageContent.CreateInputImage(new InputImage()
{
FileId = uploadResult.File!.Id,
}),
}),
}),
}),
});
# Upload the image
FILE_ID=$(mka1 llm files upload \
--file @photo.jpg \
--purpose assistants | jq -r '.id')
# Use the file_id
mka1 llm responses create \
--body "{
\"model\": \"auto\",
\"input\": [
{
\"type\": \"message\",
\"role\": \"user\",
\"content\": [
{ \"type\": \"input_text\", \"text\": \"Describe this image.\" },
{ \"type\": \"input_image\", \"file_id\": \"${FILE_ID}\" }
]
}
]
}"
# Upload the image
FILE_ID=$(curl -s https://apigw.mka1.com/api/v1/llm/files \
--header 'Authorization: Bearer <mka1-api-key>' \
--form file=@photo.jpg \
--form purpose=assistants | jq -r '.id')
# Use the file_id
curl https://apigw.mka1.com/api/v1/llm/responses \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <mka1-api-key>' \
--data "{
\"model\": \"auto\",
\"input\": [
{
\"type\": \"message\",
\"role\": \"user\",
\"content\": [
{ \"type\": \"input_text\", \"text\": \"Describe this image.\" },
{ \"type\": \"input_image\", \"file_id\": \"${FILE_ID}\" }
]
}
]
}"