Function reference

Chat model providers

Start a chat with a particular large language model (llm) provider.

ChatAnthropic Chat with an Anthropic Claude model.
ChatAzureOpenAI Chat with a model hosted on Azure OpenAI.
ChatBedrockAnthropic Chat with an AWS bedrock model.
ChatGithub Chat with a model hosted on the GitHub model marketplace.
ChatGoogle Chat with a Google Gemini model.
ChatGroq Chat with a model hosted on Groq.
ChatOllama Chat with a local Ollama model.
ChatOpenAI Chat with an OpenAI model.
ChatPerplexity Chat with a model hosted on perplexity.ai.

The chat object

Methods and attributes available on a chat instance

Chat A chat object that can be used to interact with a language model.

Image input

Submit image input to the chat

content_image_file Encode image content from a file for chat input.
content_image_plot Encode the current matplotlib plot as an image for chat input.
content_image_url Encode image content from a URL for chat input.

Tool calling

Add context to python function before registering it as a tool.

Tool Define a tool

Turns

A provider-agnostic representation of content generated during an assistant/user turn.

Turn A user or assistant turn

Query token usage

token_usage Report on token usage in the current session

Implement a model provider

Provider A model provider interface for a Chat.

User-facing types

types.Content Base class for all content types that can be appear in a Turn
types.ContentImage
types.ContentImageInline
types.ContentImageRemote
types.ContentJson
types.ContentText
types.ContentToolRequest
types.ContentToolResult
types.ChatResponse Chat response object.
types.ChatResponseAsync Chat response (async) object.
types.ImageContentTypes Allowable content types for images.
types.MISSING_TYPE A singleton representing a missing value.
types.MISSING
types.SubmitInputArgsT A TypedDict representing the arguments that can be passed to the .chat()
types.TokenUsage Token usage for a given provider (name).