---
agent:
  instructions: "Search the site by keyword or question. The search API returns Markdown."
  endpoint: "https://platform.invideo.io/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# OpenAI media

> Generate images, transcribe audio and create speech with the OpenAI SDK, the Vercel AI SDK, LiteLLM or n8n. Change the base URL and the model.

These endpoints take OpenAI's request and answer in OpenAI's shape, so the OpenAI SDK works as it is.

Base URL:

```text
https://platform-api.invideo.io/v1
```


| Endpoint | Models |
| --- | --- |
| `POST /v1/images/generations`, `POST /v1/images/edits` | every image model |
| `POST /v1/audio/transcriptions` | every speech-to-text model |
| `POST /v1/audio/speech` | every text-to-speech model |

## Images

```python
import os, base64
from openai import OpenAI

client = OpenAI(api_key=os.environ["INVIDEO_API_KEY"], base_url="https://platform-api.invideo.io/v1")

result = client.images.generate(model="nano-banana-2-1", prompt="A red fox in fresh snow, golden hour", size="1536x1024")
open("fox.png", "wb").write(base64.b64decode(result.data[0].b64_json))
```

- The image comes back as `b64_json`. With `response_format="url"` you get a link of ours instead.
- `size` becomes the model's closest aspect ratio. `quality` and `background` are passed to models that have them.
- `images.edit` sends your `image` (one or several) with the prompt. A `mask` is not supported.
- `n` must be 1: each image is priced and billed as its own request.

## Speech to text

```python
with open("meeting.mp3", "rb") as audio:
    text = client.audio.transcriptions.create(model=os.environ["INVIDEO_TRANSCRIPTION_MODEL"], file=audio)
print(text.text)
```

Set `INVIDEO_TRANSCRIPTION_MODEL` to an enabled speech-to-text model from `GET /v1/models?modality=audio`. `response_format` can be `json`, `text`, `verbose_json` (with `words`), `srt` or `vtt`.

## Text to speech

```python
speech = client.audio.speech.create(
    model="elevenlabs-tts-multilingual-v2",
    voice=os.environ["INVIDEO_TTS_VOICE"],
    input="Welcome to the show.",
)
speech.write_to_file("welcome.mp3")
```

Set `INVIDEO_TTS_VOICE` to an ElevenLabs voice ID. You can find the model's voice inputs with `GET /v1/models/elevenlabs-tts-multilingual-v2`. Read the `Content-Type` header for the returned audio format.

## Model inputs OpenAI has no field for

```python
client.images.generate(
    model="nano-banana-2-1",
    prompt="A red fox in fresh snow",
    extra_body={"resolution": "1K"},
)
```

This example sets Nano Banana 2.1’s image resolution. `extra_body` takes the selected model’s own input names and values. Look them up with `GET /v1/models/{id}`. These calls answer when the run ends.
