Skip to main content

OpenAI integration 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 --pre

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 deprecated OpenAIResponsesClient alias points to OpenAIChatClient.

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_RESPONSES_MODEL Preferred model for OpenAIChatClient
OPENAI_CHAT_MODEL Preferred model for OpenAIChatCompletionClient
OPENAI_EMBEDDING_MODEL Preferred model for OpenAIEmbeddingClient

Model lookup order:

  • OpenAIChatClient: OPENAI_RESPONSES_MODEL -> OPENAI_MODEL
  • OpenAIChatCompletionClient: OPENAI_CHAT_MODEL -> OPENAI_MODEL
  • OpenAIEmbeddingClient: OPENAI_EMBEDDING_MODEL -> OPENAI_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_DEPLOYMENT_NAME Generic fallback deployment
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME Preferred deployment for OpenAIChatClient
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME Preferred deployment for OpenAIChatCompletionClient
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME Preferred deployment for OpenAIEmbeddingClient

Deployment lookup order:

  • OpenAIChatClient: AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME -> AZURE_OPENAI_DEPLOYMENT_NAME
  • OpenAIChatCompletionClient: AZURE_OPENAI_CHAT_DEPLOYMENT_NAME -> AZURE_OPENAI_DEPLOYMENT_NAME
  • OpenAIEmbeddingClient: AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME -> AZURE_OPENAI_DEPLOYMENT_NAME

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.0.0rc6.tar.gz (59.4 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.0.0rc6-py3-none-any.whl (66.4 kB view details)

Uploaded Python 3

File details

Details for the file agent_framework_openai-1.0.0rc6.tar.gz.

File metadata

  • Download URL: agent_framework_openai-1.0.0rc6.tar.gz
  • Upload date:
  • Size: 59.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.0.0rc6.tar.gz
Algorithm Hash digest
SHA256 f14949b202aec30df4ee1edd146b3e70b938d0fecae1396cfcae8e4e4a8cb5e9
MD5 38ceaf38650f300ecbb947591be69bc4
BLAKE2b-256 1241e662c8e377121f8ab5f393dd8fdd917a1d3d7866b37aefea31d6e887e05a

See more details on using hashes here.

File details

Details for the file agent_framework_openai-1.0.0rc6-py3-none-any.whl.

File metadata

  • Download URL: agent_framework_openai-1.0.0rc6-py3-none-any.whl
  • Upload date:
  • Size: 66.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.0.0rc6-py3-none-any.whl
Algorithm Hash digest
SHA256 fb64d8c4087c2d1662680ec6f2371af9f021ed53931ff2df091c54512ffe400f
MD5 169dd3f30a12181e37800c03584d1091
BLAKE2b-256 287a9a46ab16e7682919a11108b93d0b103ec148552103ce57e9fdad3bb0e050

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