# Video in

Send a clip with your question; get an answer about it.

1. [Pick a model that watches](#1-pick-a-model-that-watches).
2. [Add the clip as a part of your message](#2-add-the-clip-as-a-part-of-your-message).
3. [Read the answer](#3-read-the-answer).

## 1. Pick a model that watches

Only some text models take video. [Models that take video in](/models?modality=text&input_modality=video) lists them; the sample below uses `google/gemini-2.5-flash`.

<div class="watch-out">
<p>Send a clip only to a model whose list holds video. A model that does not watch cannot answer about it, and the request fails.</p>
</div>

## 2. Add the clip as a part of your message

A message's `content` is a text, or a list of parts. To send a clip, make it a list: one `text` part for your question, one `video_url` part for the clip.

| Part | Holds |
|---|---|
| `{"type": "text", "text": "..."}` | your question |
| `{"type": "video_url", "video_url": {"url": "..."}}` | the clip: a public link, or the clip itself as a `data:video/mp4;base64,...` URL |

The formats are `mp4`, `mpeg`, `mov` and `webm`.

```python
import base64
import json
import os
import urllib.request

API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/chat/completions"
MODEL = "google/gemini-2.5-flash"
PROMPT = "Describe what happens in this clip."
CLIP_FILE = "clip.mp4"

with open(CLIP_FILE, "rb") as file:
    clip = base64.b64encode(file.read()).decode()

body = {
    "model": MODEL,
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": PROMPT},
                {
                    "type": "video_url",
                    "video_url": {"url": "data:video/mp4;base64," + clip},
                },
            ],
        }
    ],
}

request = urllib.request.Request(
    ADDRESS,
    data=json.dumps(body).encode(),
    headers={
        "Authorization": "Bearer " + API_KEY,
        "Content-Type": "application/json",
    },
)
with urllib.request.urlopen(request) as response:
    reply = json.load(response)

print(reply["choices"][0]["message"]["content"])
print(reply["usage"]["cost"])
```

```javascript
import { readFileSync } from "node:fs";

const API_KEY = process.env.OPENDUNES_API_KEY;
const ADDRESS = "https://opendunes.com/v1/chat/completions";
const MODEL = "google/gemini-2.5-flash";
const PROMPT = "Describe what happens in this clip.";
const CLIP_FILE = "clip.mp4";

const clip = readFileSync(CLIP_FILE).toString("base64");

const response = await fetch(ADDRESS, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: MODEL,
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: PROMPT },
          {
            type: "video_url",
            video_url: { url: `data:video/mp4;base64,${clip}` },
          },
        ],
      },
    ],
  }),
});
const reply = await response.json();

console.log(reply.choices[0].message.content);
console.log(reply.usage.cost);
```

```go
package main

import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

const (
	address  = "https://opendunes.com/v1/chat/completions"
	model    = "google/gemini-2.5-flash"
	prompt   = "Describe what happens in this clip."
	clipFile = "clip.mp4"
)

func main() {
	apiKey := os.Getenv("OPENDUNES_API_KEY")

	bytesRead, err := os.ReadFile(clipFile)
	if err != nil {
		panic(err)
	}
	clip := base64.StdEncoding.EncodeToString(bytesRead)

	body, err := json.Marshal(map[string]any{
		"model": model,
		"messages": []any{
			map[string]any{
				"role": "user",
				"content": []any{
					map[string]any{"type": "text", "text": prompt},
					map[string]any{
						"type": "video_url",
						"video_url": map[string]any{
							"url": "data:video/mp4;base64," + clip,
						},
					},
				},
			},
		},
	})
	if err != nil {
		panic(err)
	}

	request, err := http.NewRequest("POST", address, bytes.NewReader(body))
	if err != nil {
		panic(err)
	}
	request.Header.Set("Authorization", "Bearer "+apiKey)
	request.Header.Set("Content-Type", "application/json")

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	var reply struct {
		Choices []struct {
			Message struct {
				Content string `json:"content"`
			} `json:"message"`
		} `json:"choices"`
		Usage struct {
			Cost float64 `json:"cost"`
		} `json:"usage"`
	}
	if err := json.NewDecoder(response.Body).Decode(&reply); err != nil {
		panic(err)
	}
	fmt.Println(reply.Choices[0].Message.Content)
	fmt.Println(reply.Usage.Cost)
}
```

```bash cURL
ADDRESS="https://opendunes.com/v1/chat/completions"
MODEL="google/gemini-2.5-flash"
PROMPT="Describe what happens in this clip."
CLIP_FILE="clip.mp4"

CLIP=$(base64 < "$CLIP_FILE" | tr -d '\n')

curl "$ADDRESS" \
  -H "Authorization: Bearer $OPENDUNES_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{
  "model": "$MODEL",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "$PROMPT"
        },
        {
          "type": "video_url",
          "video_url": {
            "url": "data:video/mp4;base64,$CLIP"
          }
        }
      ]
    }
  ]
}
EOF
```

<div class="do">
<p>Send a public link when the clip is online, and a <code>data:</code> URL when it is a file on your side. The whole request stays under 32 MB, so keep a clip you send this way short.</p>
</div>

<div class="dont">
<p>Don't send a link that needs a sign-in to open. The model cannot sign in, and the request fails.</p>
</div>

## 3. Read the answer

The answer is the text in `choices[0].message.content`, as on any text request. The clip is charged as video input, counted in `usage.prompt_tokens_details.video_tokens`, and `usage.cost` is the whole charge.

To send the answer back as a stream, see [Streaming](/docs/streaming). Every field of the request: [Chat](/docs/reference/chat-completions).

Clips made from words, not sent in, are in [Video](/docs/video).

<div class="good-to-know">
<p>A batch does not take video. Send the request on its own: see <a href="/docs/batches">Batches</a>.</p>
</div>

## Errors

The body says why. What to do on every status: [Errors and retries](/docs/errors-and-retries).

| Status | Means |
|---|---|
| 400 | the model takes no video, or the clip is in a format it does not read |
| 402 | the balance cannot cover the request |
| 404 | no such model |
| 413 | the request is larger than the door takes |
