AI Gateway/Multimodal
Video Inputs
Send video files to video-capable models through the Agnic AI Gateway
Video Inputs
Send video files to compatible models for analysis, description, object detection, and action recognition. Agnic supports multiple video formats for comprehensive video understanding tasks.
Overview
Video requests are available via the /v1/chat/completions API with the video_url content type. Videos can be sent as URLs or base64-encoded data URLs.
Video URL support varies by provider. Some providers only support specific URL types (e.g., YouTube links for certain Google models).
Using Video URLs
For publicly accessible videos:
Python
from openai import OpenAI
client = OpenAI(
api_key="agnic_tok_YOUR_TOKEN",
base_url="https://api.agnic.ai/v1"
)
response = client.chat.completions.create(
model="google/gemini-2.0-flash",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Please describe what's happening in this video."
},
{
"type": "video_url",
"video_url": {
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
}
]
}
]
)
print(response.choices[0].message.content)JavaScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'agnic_tok_YOUR_TOKEN',
baseURL: 'https://api.agnic.ai/v1'
});
const response = await client.chat.completions.create({
model: 'google/gemini-2.0-flash',
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: "Please describe what's happening in this video."
},
{
type: 'video_url',
video_url: {
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
}
}
]
}
]
});
console.log(response.choices[0].message.content);Using Base64 Encoded Videos
For local video files:
Python
from openai import OpenAI
import base64
def encode_video(video_path):
with open(video_path, "rb") as video_file:
return base64.b64encode(video_file.read()).decode('utf-8')
client = OpenAI(
api_key="agnic_tok_YOUR_TOKEN",
base_url="https://api.agnic.ai/v1"
)
# Read and encode the video
video_path = "path/to/your/video.mp4"
base64_video = encode_video(video_path)
data_url = f"data:video/mp4;base64,{base64_video}"
response = client.chat.completions.create(
model="google/gemini-2.0-flash",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "What's happening in this video?"
},
{
"type": "video_url",
"video_url": {
"url": data_url
}
}
]
}
]
)
print(response.choices[0].message.content)JavaScript
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
apiKey: 'agnic_tok_YOUR_TOKEN',
baseURL: 'https://api.agnic.ai/v1'
});
// Read and encode the video
const videoPath = 'path/to/your/video.mp4';
const videoBuffer = fs.readFileSync(videoPath);
const base64Video = videoBuffer.toString('base64');
const dataUrl = `data:video/mp4;base64,${base64Video}`;
const response = await client.chat.completions.create({
model: 'google/gemini-2.0-flash',
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: "What's happening in this video?"
},
{
type: 'video_url',
video_url: {
url: dataUrl
}
}
]
}
]
});
console.log(response.choices[0].message.content);Supported Video Formats
| Format | MIME Type | Extension |
|---|---|---|
| MP4 | video/mp4 | .mp4 |
| MPEG | video/mpeg | .mpeg |
| MOV | video/mov | .mov |
| WebM | video/webm | .webm |
Compatible Models
Models with video processing capabilities:
| Provider | Models | URL Support |
|---|---|---|
| Gemini 2.0 Flash, Gemini 1.5 Pro | YouTube links |
Use Cases
- Video summarization - Generate text summaries
- Object recognition - Identify objects and people
- Action detection - Describe activities and movements
- Scene understanding - Analyze settings and contexts
- Content moderation - Review video content
- Sports analysis - Analyze gameplay and movements
Best Practices
File Size Considerations
- Compress videos - Reduce size without losing quality
- Trim videos - Include only relevant segments
- Lower resolution - 720p is often sufficient
- Reduce frame rate - Lower FPS for non-critical analysis
Optimal Video Length
- Check model-specific limits on duration
- Split long videos into shorter segments
- Focus on key moments
Quality vs. Size Trade-offs
| Quality | Resolution | Use Case |
|---|---|---|
| High | 1080p+ | Detailed analysis, text recognition |
| Medium | 720p | General analysis |
| Lower | 480p | Basic scene understanding |
Troubleshooting
Video not processing?
- Verify the model supports video input
- Check format compatibility
- Try base64 encoding instead of URL
- Ensure file isn't corrupted
Large file errors?
- Compress the video
- Reduce resolution or frame rate
- Trim to shorter duration
Poor analysis?
- Ensure video quality is sufficient
- Provide specific prompts
- Check if content is clearly visible