Generate a text response
Generate text from a prompt or conversation history.- Python
- curl
Send a chat completion request using the OpenAI Python SDK:The response should be similar to:
generate-text.py
Stream a text response
Setstream=True to receive tokens as they are generated instead of waiting
for the full response.
- Python
- curl
Set
stream=True and iterate over the response chunks as they arrive:stream-text.py
Analyze an image
Provide an image and a text prompt to generate a description of or extract information from visual content. Include the image in themessages array using an image_url content item. The
url field accepts either a publicly accessible URL or a base64-encoded data
URI (for example, data:image/jpeg;base64,...).
The following example asks the model to describe the contents of an image.
- Python
- curl
Include an The response should be similar to:
image_url content block alongside your text prompt:generate-image-description.py
Analyze a video
Provide a video and a text prompt to generate a natural-language description or analysis of the video’s visual content. Include the video in themessages array using a video_url content item. The
url field accepts either a publicly accessible URL or a base64-encoded data
URI (for example, data:video/mp4;base64,...).
The following example asks the model to describe the contents of a video.
- Python
- curl
Pass a video URL and a text question to get a natural-language description of
the video:The response should be similar to:
generate-video-description.py