Skip to main content

Module responses

Module responses 

Source
Expand description

AzureOpenAIResponsesClient: a ChatClient for the Responses API on Azure OpenAI (POST {endpoint}/openai/v1/responses).

§URL shape and api-version

Unlike AzureOpenAIClient (Chat Completions, which selects the model via a deployment-scoped URL — .../openai/deployments/{deployment}/chat/completions), the Responses API on Azure OpenAI is documented upstream as supported only through the newer, OpenAI-compatible “v1 preview” surface: there is no deployment segment in the URL at all, and the deployment instead flows into the request body’s model field, exactly like the plain OpenAIChatClient.

This mirrors upstream AzureOpenAIResponsesClient.__init__ (azure/_responses_client.py:99-146), which:

  • forces default_api_version="preview" when building its settings (_responses_client.py:112) — distinct from every other Azure OpenAI client’s "2024-10-21" default (azure/_shared.py:28, crate::AzureOpenAIClient’s own default);
  • auto-derives base_url = urljoin(endpoint, "/openai/v1/") for standard *.openai.azure.com endpoints when no explicit base_url is given (_responses_client.py:117-123), and documents that “currently, the base_url must end with /openai/v1/” and “the api_version must be preview” (_responses_client.py:60-65);
  • requires a deployment name, raising if one isn’t configured (_responses_client.py:127-131).

This client always derives the /openai/v1/ route from endpoint (skipping upstream’s .openai.azure.com-hostname sniff, which its own comment flags as “a temporary hack” for a case the Rust port doesn’t need to special-case); with_base_url is the escape hatch upstream’s base_url parameter provides for full control.

§Conversion and streaming

Request/response conversion (messages → input items, tool specs, output parsing, SSE event parsing) is reused verbatim from agent_framework_openai::responses rather than duplicated — only the URL shape, api-version default, and authentication differ, exactly as AzureOpenAIClient reuses [agent_framework_openai::convert] for Chat Completions. conversation_idprevious_response_id and store ↔ auto-populated conversation_id behave identically to OpenAIChatClient because the same conversion functions are called.

use agent_framework_azure::responses::AzureOpenAIResponsesClient;
use agent_framework_core::prelude::*;

let client = AzureOpenAIResponsesClient::new(
    "https://my-resource.openai.azure.com",
    "my-gpt4o-deployment",
    "my-api-key",
);
let agent = Agent::builder(client)
    .instructions("You are concise.")
    .build();
let reply = agent.run_once("Say hi").await?;
println!("{}", reply.text());

Entra ID (bearer token) authentication instead of a static key — the same TokenCredential plumbing AzureOpenAIClient uses (e.g. the "https://cognitiveservices.azure.com/.default" scope):

use std::sync::Arc;
use agent_framework_azure::StaticTokenCredential;
use agent_framework_azure::responses::AzureOpenAIResponsesClient;

let credential = Arc::new(StaticTokenCredential::new("eyJ0eXAi..."));
let client = AzureOpenAIResponsesClient::with_token_credential(
    "https://my-resource.openai.azure.com",
    "my-gpt4o-deployment",
    credential,
);

Structs§

AzureOpenAIResponsesClient
An Azure OpenAI Responses API chat client (POST {endpoint}/openai/v1/responses).