ReqLLM.Providers.Azure.OpenAI (ReqLLM v1.14.0)

View Source

OpenAI model family support for Azure OpenAI Service.

Handles OpenAI models (GPT-4o, GPT-4, etc.) deployed on Azure.

This module acts as a thin adapter between Azure's deployment-based API and OpenAI's native Chat Completions format, delegating encoding to ReqLLM.Provider.Defaults and applying Azure-specific modifications.

Key Differences from Standard OpenAI

  • No model field in request body (deployment determines the model)
  • Uses same message and tool format as OpenAI Chat API

Reasoning Model Support

For reasoning models (o1, o3, o4, gpt-4.1, gpt-5), this module automatically:

  • Uses max_completion_tokens instead of max_tokens
  • Supports reasoning_effort option (via provider_options)

Structured Output Support

Structured output is supported via tools with strict mode. When a tool has strict: true, this module automatically:

  • Sets additionalProperties: false on the parameters schema
  • Makes all properties required

For structured output generation, use ReqLLM.generate_object/4 which creates a synthetic tool to enforce the output schema.

Additional Options

  • n: Number of completions to generate (integer, default 1)
  • parallel_tool_calls: Whether to allow parallel tool calls (boolean)
  • service_tier: Request prioritization ("auto", "default", "priority")

Summary

Functions

Decodes Server-Sent Events for streaming responses.

Extracts usage information from Azure OpenAI response.

Formats an embedding request for Azure OpenAI.

Formats a ReqLLM context into OpenAI Chat Completions request format.

Parses an Azure OpenAI response into ReqLLM format.

Pre-validates and transforms options for OpenAI models on Azure. Warns if Anthropic-specific options are passed.

Functions

decode_stream_event(event, model)

Decodes Server-Sent Events for streaming responses.

Uses the same SSE format as standard OpenAI.

extract_usage(body, arg2)

Extracts usage information from Azure OpenAI response.

Includes all available fields: input_tokens, output_tokens, total_tokens, cached_tokens (from prompt_tokens_details), and reasoning_tokens (from completion_tokens_details, or inferred from reasoning_content in choices).

format_embedding_request(model_id, text, opts)

Formats an embedding request for Azure OpenAI.

Embedding-specific options (dimensions, encoding_format) are read from provider_options where they are placed after schema validation and hoisting.

format_request(model_id, context, opts)

Formats a ReqLLM context into OpenAI Chat Completions request format.

Delegates encoding to ReqLLM.Provider.Defaults.default_build_body/1 then applies Azure-specific modifications:

  • Removes model field (Azure uses deployment-based routing)
  • Adds token limits appropriate for model type (reasoning vs standard)
  • Adds Azure-specific options (service_tier, reasoning_effort)

Returns a map ready to be JSON-encoded for the Azure OpenAI API.

parse_response(body, model, opts)

Parses an Azure OpenAI response into ReqLLM format.

Uses the centralized OpenAI response decoding from Provider.Defaults.

pre_validate_options(operation, model, opts)

Pre-validates and transforms options for OpenAI models on Azure. Warns if Anthropic-specific options are passed.