Skip to main content
To generate text with an LLM, you need to use the chat completions API. This API allows you to send text, images, and videos with your request, using an OpenAI-compatible interface, as shown in the following examples. The examples below use the minimax-m3 model, but you can replace it with any supported model that’s listed as an “LLM” type.

Requirements

  • An API key. The code below assumes you set it in an environment variable:
  • The openai Python package. You can install it with this command:

Generate a text response

Here’s how you can generate text from a prompt or conversation history.

Stream a text response

Set stream=True to receive tokens as they are generated instead of waiting for the full response.

Analyze an image

Some LLMs accept images, allowing them to generate a description or analysis of the image visual content. You can use any supported model that’s both an “LLM” and a “Vision” type. To pass an image, add the image_url attribute in the messages.content object. The inner url attribute accepts either a publicly accessible URL or a base64-encoded data URI (for example, data:image/jpeg;base64,...). Notice that content is an array, allowing you to pass multiple images at once.

Analyze a video

Some LLMs accept video input, allowing them to generate a description or analysis of the video’s visual content. You can use any supported model that’s both an “LLM” and a “Vision” type. To pass a video, add the video_url attribute in the messages.content object. The inner url attribute accepts either a publicly accessible URL or a base64-encoded data URI (for example, data:video/mp4;base64,...). Notice that content is an array, allowing you to pass multiple videos at once, or even a combination of videos and images.