Skip to main content
Generate text from a prompt or conversation with /v1/chat/completions, or analyze images and video by passing them alongside text in the same request. The endpoint is fully compatible with the OpenAI Chat Completions API, so existing OpenAI SDK code works unchanged. Check the supported models page to see which models are available via shared or dedicated endpoints, and which support text generation versus image/video analysis.
Already using the OpenAI SDK? Just change base_url to https://api.modular.com/v1 and set api_key to your API key. No other code changes required.

The v1/chat/completions endpoint

The v1/chat/completions endpoint supports both single-turn and multi-turn interactions. You provide a sequence of structured messages with roles (system, user, assistant), and the model generates a response. For example, within the v1/chat/completions request body, the "messages" array might look similar to the following:
Use a combination of roles to give the model the context it needs. A system message can define overall model response behavior, user messages represent instructions or prompts from the end-user, and assistant messages incorporate past model responses into the context. You can also include image or video inputs alongside text to work with multimodal models.

Generate text

Generate text from a prompt or conversation history using v1/chat/completions:
Send a chat completion request using the OpenAI Python SDK:
generate-text.py

Stream responses in real time

Set stream=True to receive tokens as they are generated instead of waiting for the full response:
Set stream=True and iterate over the response chunks as they arrive:
stream-text.py

Analyze images

Send images to the model alongside text prompts to get descriptions, answers to questions, or extracted information from visual content.

Pass image or video URLs

Within the v1/chat/completions request body, the "messages" array accepts inline image or video URLs.
Use image_url to pass an image:
Both image_url and video_url also accept base64-encoded data URIs (such as data:image/jpeg;base64,... or data:video/mp4;base64,...).

Describe an image

Send an image URL alongside a text question to get a description or analysis of the image:
Include an image_url content block alongside your text prompt:
generate-image-description.py

Describe video content

Send a video URL alongside a text question to get a description or analysis of the video’s visual content.

Describe a video

Include a video_url content block in your request to analyze what happens in a video:
Pass a video URL and a text question to get a natural-language description of the video:
generate-video-description.py