Skip to main content

OpenAI integrations for Microsoft Agent Framework.

Project description

agent-framework-openai

OpenAI integration for Microsoft Agent Framework.

This package provides:

  • OpenAIChatClient for the OpenAI Responses API
  • OpenAIChatCompletionClient for the Chat Completions API
  • OpenAIEmbeddingClient for embeddings

Installation

pip install agent-framework-openai

Which chat client should I use?

Use OpenAIChatClient for new work unless you specifically need the Chat Completions API.

  • OpenAIChatClient uses the Responses API and is the preferred general-purpose chat client.
  • OpenAIChatCompletionClient uses the Chat Completions API and is mainly for compatibility with existing Chat Completions-based integrations.

The previous deprecated Responses alias has been removed. Use OpenAIChatClient directly.

Environment variables

OpenAI

These variables are used when the client is configured for OpenAI:

Variable Purpose
OPENAI_API_KEY OpenAI API key
OPENAI_ORG_ID OpenAI organization ID
OPENAI_BASE_URL Custom OpenAI-compatible base URL
OPENAI_MODEL Generic fallback model
OPENAI_CHAT_MODEL Preferred model for OpenAIChatClient
OPENAI_CHAT_COMPLETION_MODEL Preferred model for OpenAIChatCompletionClient
OPENAI_EMBEDDING_MODEL Preferred model for OpenAIEmbeddingClient

Model lookup order:

  • OpenAIChatClient: OPENAI_CHAT_MODEL -> OPENAI_MODEL
  • OpenAIChatCompletionClient: OPENAI_CHAT_COMPLETION_MODEL -> OPENAI_MODEL
  • OpenAIEmbeddingClient: OPENAI_EMBEDDING_MODEL -> OPENAI_MODEL

These model variables are only consulted when you do not pass model= directly. In other words, OpenAIChatClient(model="...") ignores OPENAI_CHAT_MODEL, and OpenAIChatCompletionClient(model="...") ignores OPENAI_CHAT_COMPLETION_MODEL.

Azure OpenAI

These variables are used when the client is configured for Azure OpenAI:

Variable Purpose
AZURE_OPENAI_ENDPOINT Azure OpenAI resource endpoint
AZURE_OPENAI_BASE_URL Full Azure OpenAI base URL (.../openai/v1)
AZURE_OPENAI_API_KEY Azure OpenAI API key
AZURE_OPENAI_API_VERSION Azure OpenAI API version
AZURE_OPENAI_MODEL Generic fallback deployment
AZURE_OPENAI_CHAT_MODEL Preferred deployment for OpenAIChatClient
AZURE_OPENAI_CHAT_COMPLETION_MODEL Preferred deployment for OpenAIChatCompletionClient
AZURE_OPENAI_EMBEDDING_MODEL Preferred deployment for OpenAIEmbeddingClient

Deployment lookup order:

  • OpenAIChatClient: AZURE_OPENAI_CHAT_MODEL -> AZURE_OPENAI_MODEL
  • OpenAIChatCompletionClient: AZURE_OPENAI_CHAT_COMPLETION_MODEL -> AZURE_OPENAI_MODEL
  • OpenAIEmbeddingClient: AZURE_OPENAI_EMBEDDING_MODEL -> AZURE_OPENAI_MODEL

For Azure routing, the same rule applies: the client-specific deployment variable is checked first, then the generic AZURE_OPENAI_MODEL fallback. Passing model= overrides both environment variables.

When both OpenAI and Azure environment variables are present, the generic clients prefer OpenAI when OPENAI_API_KEY is configured. To use Azure explicitly, pass azure_endpoint or credential.

OpenAI example

from agent_framework.openai import OpenAIChatClient

client = OpenAIChatClient(model="gpt-4.1")

Azure OpenAI example

from azure.identity.aio import AzureCliCredential

from agent_framework.openai import OpenAIChatClient

client = OpenAIChatClient(
    model="my-responses-deployment",
    azure_endpoint="https://my-resource.openai.azure.com",
    credential=AzureCliCredential(),
)

ChatClient vs ChatCompletionClient

Use OpenAIChatClient when you want the Responses API as your default chat surface.

Use OpenAIChatCompletionClient when you specifically need the Chat Completions API:

from agent_framework.openai import OpenAIChatCompletionClient

client = OpenAIChatCompletionClient(model="gpt-4o-mini")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_framework_openai-1.2.1.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_framework_openai-1.2.1-py3-none-any.whl (50.8 kB view details)

Uploaded Python 3

File details

Details for the file agent_framework_openai-1.2.1.tar.gz.

File metadata

  • Download URL: agent_framework_openai-1.2.1.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agent_framework_openai-1.2.1.tar.gz
Algorithm Hash digest
SHA256 2c9f620bed28992661c2e6301c2ee03c4cc7c95dac486a75c49fc48f887af4f5
MD5 f827794365a4e707833f4c54fce3cad2
BLAKE2b-256 71a491f354cc20a549e2f708aa10d621ca87175dd02061de51fd162ff3e8afb2

See more details on using hashes here.

File details

Details for the file agent_framework_openai-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: agent_framework_openai-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 50.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agent_framework_openai-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3d547ceec3dc204affa4857864d238c80fa29309d0d879f5f5d41577086a33b
MD5 6e0fe669d6252a07a3685c234b3646a7
BLAKE2b-256 c6abb35553b0b4b3a7979a19c29b0ec7a1cb5ad02cebbcc528864cc79f85b07b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page