azure.openai.chat
Module azure.openai.chat
Definitions
ballerinax/azure.openai.chat Ballerina library
Ballerina Azure OpenAI Chat Completions connector
Overview
Azure OpenAI provides access to OpenAI's powerful language models including GPT-4o, GPT-4, and o-series models through Microsoft Azure's enterprise-grade infrastructure. It combines OpenAI's advanced AI capabilities with Azure's security, compliance, and regional availability features.
The ballerinax/azure.openai.chat package offers functionality to connect and interact with the Chat Completions API of the Azure AI Foundry Models Service. The Chat Completions API enables you to build conversational AI applications with features like multi-turn conversations, function/tool calling, structured outputs, and vision capabilities.
Setup guide
To use the Azure OpenAI Chat Completions Connector, you must have access to an Azure OpenAI resource through a Microsoft Azure account. If you do not have an Azure account, you can sign up for one here.
Create an Azure OpenAI resource and obtain the API key
-
Sign in to the Azure Portal.
-
Search for "Azure OpenAI" in the top search bar and select Azure OpenAI from the results.
-
Click Create to create a new Azure OpenAI resource. Fill in the required details such as subscription, resource group, region, and resource name, then click Review + create and finally Create.
-
Once the resource is deployed, navigate to your Azure OpenAI resource.
-
In the left-hand menu, go to Resource Management -> Keys and Endpoint.
-
Copy one of the provided keys (Key 1 or Key 2) and the endpoint URL. Store them securely to use in your application.
-
Append
/openai/v1to the endpoint URL. The portal shows the resource root (for examplehttps://<resource-name>.openai.azure.com/), while this connector targets the v1 API surface, so the value to pass asserviceUrlishttps://<resource-name>.openai.azure.com/openai/v1. Resources provisioned through Azure AI Foundry may instead showhttps://<resource-name>.services.ai.azure.com/, which becomeshttps://<resource-name>.services.ai.azure.com/openai/v1.
Quickstart
To use the Azure OpenAI Chat Completions connector in your Ballerina application, update the .bal file as follows:
Step 1: Import the module
Import the ballerinax/azure.openai.chat module.
import ballerinax/azure.openai.chat;
Step 2: Create a new connector instance
Create a chat:Client with your Azure OpenAI resource endpoint and one credential. Azure
accepts either an API key or a Microsoft Entra ID access token, and the two are alternatives —
provide whichever you have, not both.
serviceUrl must be the endpoint including the /openai/v1 base path, as described in step 7 of the setup
guide — https://<resource-name>.openai.azure.com/openai/v1. Passing the bare resource root makes every request
return 404.
Using the API key obtained in the setup guide:
configurable string apiKey = ?; configurable string serviceUrl = ?; final chat:Client azureOpenAIChat = check new ({ auth: { api\-key: apiKey } }, serviceUrl);
Alternatively, using a Microsoft Entra ID access token, which is sent as an Authorization: Bearer
header:
configurable string token = ?; configurable string serviceUrl = ?; final chat:Client azureOpenAIChat = check new ({ auth: { token } }, serviceUrl);
Step 3: Invoke the connector operation
Now, you can utilize available connector operations.
Create a chat completion
public function main() returns error? { chat:ChatCompletionsBody request = { model: "gpt-4o-mini", messages: [ {role: "user", "content": "What is the Ballerina programming language?"} ] }; chat:InlineResponse200 response = check azureOpenAIChat->/chat/completions.post(request); }
Step 4: Run the Ballerina application
bal run
Examples
The Azure OpenAI Chat Completions connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
- Chat completion - Create a basic chat completion using the Azure OpenAI Chat Completions API.
- Function calling - Use function/tool calling to extend the model's capabilities with custom functions.
Clients
azure.openai.chat: Client
Constructor
Gets invoked to initialize the connector.
init (ConnectionConfig config, string serviceUrl)- config ConnectionConfig - The configurations to be used when initializing the
connector
- serviceUrl string - URL of the target service
post chat/completions
function post chat/completions(ChatCompletionsBody payload, map<string|string[]> headers, *CreateChatCompletionQueries queries) returns InlineResponse200|errorCreates a chat completion.
Parameters
- payload ChatCompletionsBody -
- queries *CreateChatCompletionQueries - Queries to be sent with the request
Return Type
- InlineResponse200|error - The request has succeeded.
Records
azure.openai.chat: ApiKeysConfig
Provides API key configurations needed when communicating with a remote HTTP endpoint.
Fields
- api\-key string -
azure.openai.chat: AzureContentFilterBlocklistResult
A collection of true/false filtering results for configured custom blocklists.
Fields
- filtered boolean - A value indicating whether any of the detailed blocklists resulted in a filtering action.
- details? AzureContentFilterBlocklistResultDetails[] - The pairs of individual blocklist IDs and whether they resulted in a filtering action.
azure.openai.chat: AzureContentFilterBlocklistResultDetails
Fields
- filtered boolean - A value indicating whether the blocklist produced a filtering action.
- id string - The ID of the custom blocklist evaluated.
azure.openai.chat: AzureContentFilterCompletionTextSpan
A representation of a span of completion text as used by Azure OpenAI content filter results.
Fields
- completion_start_offset Signed32 - Offset of the UTF32 code point which begins the span.
- completion_end_offset Signed32 - Offset of the first UTF32 code point which is excluded from the span. This field is always equal to completion_start_offset for empty spans. This field is always larger than completion_start_offset for non-empty spans.
azure.openai.chat: AzureContentFilterCompletionTextSpanDetectionResult
Fields
- filtered boolean - Whether the content detection resulted in a content filtering action.
- detected boolean - Whether the labeled content category was detected in the content.
- details AzureContentFilterCompletionTextSpan[] - Detailed information about the detected completion text spans.
azure.openai.chat: AzureContentFilterCustomTopicResult
A collection of true/false filtering results for configured custom topics.
Fields
- filtered boolean - A value indicating whether any of the detailed topics resulted in a filtering action.
- details? AzureContentFilterCustomTopicResultDetails[] - The pairs of individual topic IDs and whether they are detected.
azure.openai.chat: AzureContentFilterCustomTopicResultDetails
Fields
- detected boolean - A value indicating whether the topic is detected.
- id string - The ID of the custom topic evaluated.
azure.openai.chat: AzureContentFilterDetectionResult
A labeled content filter result item that indicates whether the content was detected and whether the content was filtered.
Fields
- filtered boolean - Whether the content detection resulted in a content filtering action.
- detected boolean - Whether the labeled content category was detected in the content.
azure.openai.chat: AzureContentFilterResultForChoice
A content filter result for a single response item produced by a generative AI system.
Fields
- sexual? AzureContentFilterSeverityResult - A content filter category for language related to anatomical organs and genitals, romantic relationships, acts portrayed in erotic or affectionate terms, pregnancy, physical sexual acts, including those portrayed as an assault or a forced sexual violent act against one's will, prostitution, pornography, and abuse.
- hate? AzureContentFilterSeverityResult - A content filter category that can refer to any content that attacks or uses pejorative or discriminatory language with reference to a person or identity group based on certain differentiating attributes of these groups including but not limited to race, ethnicity, nationality, gender identity and expression, sexual orientation, religion, immigration status, ability status, personal appearance, and body size.
- violence? AzureContentFilterSeverityResult - A content filter category for language related to physical actions intended to hurt, injure, damage, or kill someone or something; describes weapons, guns and related entities, such as manufactures, associations, legislation, and so on.
- self_harm? AzureContentFilterSeverityResult - A content filter category that describes language related to physical actions intended to purposely hurt, injure, damage one's body or kill oneself.
- profanity? AzureContentFilterDetectionResult - A detection result that identifies whether crude, vulgar, or otherwise objection language is present in the content.
- custom_blocklists? AzureContentFilterBlocklistResult - A collection of binary filtering outcomes for configured custom blocklists.
- custom_topics? AzureContentFilterCustomTopicResult - A collection of binary filtering outcomes for configured custom topics.
- 'error? AzureContentFilterResultForChoiceError - If present, details about an error that prevented content filtering from completing its evaluation.
- protected_material_text? AzureContentFilterDetectionResult - A detection result that describes a match against text protected under copyright or other status.
- protected_material_code? AzureContentFilterResultForChoiceProtectedMaterialCode - A detection result that describes a match against licensed code or other protected source material.
- ungrounded_material? AzureContentFilterCompletionTextSpanDetectionResult -
- personally_identifiable_information? AzureContentFilterPersonallyIdentifiableInformationResult - A detection result that describes matches against Personal Identifiable Information with configurable subcategories.
azure.openai.chat: AzureContentFilterResultForChoiceError
If present, details about an error that prevented content filtering from completing its evaluation.
Fields
- code Signed32 - A distinct, machine-readable code associated with the error.
- message string - A human-readable message associated with the error.
azure.openai.chat: AzureContentFilterResultForChoiceProtectedMaterialCode
A detection result that describes a match against licensed code or other protected source material.
Fields
- filtered boolean - Whether the content detection resulted in a content filtering action.
- detected boolean - Whether the labeled content category was detected in the content.
- citation? AzureContentFilterResultForChoiceProtectedMaterialCodeCitation - If available, the citation details describing the associated license and its location.
azure.openai.chat: AzureContentFilterResultForChoiceProtectedMaterialCodeCitation
If available, the citation details describing the associated license and its location.
Fields
- license? string - The name or identifier of the license associated with the detection.
- URL? string - The URL associated with the license.
azure.openai.chat: AzureContentFilterResultForPrompt
A content filter result associated with a single input prompt item into a generative AI system.
Fields
- prompt_index? Signed32 - The index of the input prompt associated with the accompanying content filter result categories.
- content_filter_results? AzureContentFilterResultForPromptContentFilterResults - The content filter category details for the result.
azure.openai.chat: AzureContentFilterResultForPromptContentFilterResults
The content filter category details for the result.
Fields
- sexual? AzureContentFilterSeverityResult - A content filter category for language related to anatomical organs and genitals, romantic relationships, acts portrayed in erotic or affectionate terms, pregnancy, physical sexual acts, including those portrayed as an assault or a forced sexual violent act against one's will, prostitution, pornography, and abuse.
- hate? AzureContentFilterSeverityResult - A content filter category that can refer to any content that attacks or uses pejorative or discriminatory language with reference to a person or identity group based on certain differentiating attributes of these groups including but not limited to race, ethnicity, nationality, gender identity and expression, sexual orientation, religion, immigration status, ability status, personal appearance, and body size.
- violence? AzureContentFilterSeverityResult - A content filter category for language related to physical actions intended to hurt, injure, damage, or kill someone or something; describes weapons, guns and related entities, such as manufactures, associations, legislation, and so on.
- self_harm? AzureContentFilterSeverityResult - A content filter category that describes language related to physical actions intended to purposely hurt, injure, damage one's body or kill oneself.
- profanity? AzureContentFilterDetectionResult - A detection result that identifies whether crude, vulgar, or otherwise objection language is present in the content.
- custom_blocklists? AzureContentFilterBlocklistResult - A collection of binary filtering outcomes for configured custom blocklists.
- custom_topics? AzureContentFilterCustomTopicResult - A collection of binary filtering outcomes for configured custom topics.
- 'error? AzureContentFilterResultForChoiceError - If present, details about an error that prevented content filtering from completing its evaluation.
- jailbreak AzureContentFilterDetectionResult - A detection result that describes user prompt injection attacks, where malicious users deliberately exploit system vulnerabilities to elicit unauthorized behavior from the LLM. This could lead to inappropriate content generation or violations of system-imposed restrictions.
- indirect_attack AzureContentFilterDetectionResult - A detection result that describes attacks on systems powered by Generative AI models that can happen every time an application processes information that wasn’t directly authored by either the developer of the application or the user.
azure.openai.chat: AzureContentFilterSeverityResult
A labeled content filter result item that indicates whether the content was filtered and what the qualitative severity level of the content was, as evaluated against content filter configuration for the category.
Fields
- filtered boolean - Whether the content severity resulted in a content filtering action.
- severity "safe"|"low"|"medium"|"high" - The labeled severity of the content.
azure.openai.chat: AzureUserSecurityContext
User security context contains several parameters that describe the application itself, and the end user that interacts with the application. These fields assist your security operations teams to investigate and mitigate security incidents by providing a comprehensive approach to protecting your AI applications. Learn more about protecting AI applications using Microsoft Defender for Cloud.
Fields
- application_name? string - The name of the application. Sensitive personal information should not be included in this field.
- end_user_id? string - This identifier is the Microsoft Entra ID (formerly Azure Active Directory) user object ID used to authenticate end-users within the generative AI application. Sensitive personal information should not be included in this field.
- end_user_tenant_id? string - The Microsoft 365 tenant ID the end user belongs to. It's required when the generative AI application is multitenant.
- source_ip? string - Captures the original client's IP address.
azure.openai.chat: ChatCompletionsBody
Fields
- metadata? OpenAIMetadata - Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
- top_logprobs? int? -
- temperature? decimal? -
- top_p? decimal? -
- user? string - A unique identifier representing your end-user, which can help to monitor and detect abuse.
- safety_identifier? string - A stable identifier used to help detect users of your application that may be violating OpenAI's usage policies. The IDs should be a string that uniquely identifies each user, with a maximum length of 64 characters. We recommend hashing their username or email address, in order to avoid sending us any identifying information. Learn more.
- prompt_cache_key? string - Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces the
userfield. Learn more.
- prompt_cache_retention? "in_memory"|"24h"? -
- messages OpenAIChatCompletionRequestMessage[] - A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio.
- model string - Model ID used to generate the response, like
gpt-4ooro3. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the model guide to browse and compare available models.
- modalities? OpenAIResponseModalities? - Output types that you would like the model to generate.
Most models are capable of generating text, which is the default:
["text"]Thegpt-4o-audio-previewmodel can also be used to generate audio. To request that this model generate both text and audio responses, you can use:["text", "audio"]
- verbosity? OpenAIVerbosity? - Constrains the verbosity of the model's response. Lower values will result in
more concise responses, while higher values will result in more verbose responses.
Currently supported values are
low,medium, andhigh.
- reasoning_effort? OpenAIReasoningEffort? - Constrains effort on reasoning for
reasoning models.
Currently supported values are
none,minimal,low,medium,high, andxhigh. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.gpt-5.1defaults tonone, which does not perform reasoning. The supported reasoning values forgpt-5.1arenone,low,medium, andhigh. Tool calls are supported for all reasoning values in gpt-5.1.- All models before
gpt-5.1default tomediumreasoning effort, and do not supportnone. - The
gpt-5-promodel defaults to (and only supports)highreasoning effort. xhighis supported for all models aftergpt-5.1-codex-max.
- max_completion_tokens? int? - An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
- frequency_penalty? decimal? - Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
- presence_penalty? decimal? - Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
- response_format? OpenAICreateChatCompletionRequestResponseFormat - An object specifying the format that the model must output.
Setting to
{ "type": "json_schema", "json_schema": {...} }enables Structured Outputs which ensures the model will match your supplied JSON schema. Setting to{ "type": "json_object" }enables JSON mode, which ensures the message the model generates is valid JSON. Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off iffinish_reason="length", which indicates the generation exceededmax_tokensor the conversation exceeded the max context length.
- store? boolean? - Whether or not to store the output of this chat completion request for use in model distillation or evals products.
- 'stream? boolean? - If set to true, the model response data will be streamed to the client as it is generated using server-sent events.
- stop? OpenAIStopConfiguration - Not supported with latest reasoning models
o3ando4-mini. Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
- logit_bias? record {}? - Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
- logprobs? boolean? - Whether to return log probabilities of the output tokens or not. If true,
returns the log probabilities of each output token returned in the
contentofmessage.
- max_tokens? int? - The maximum number of tokens that can be generated in the chat completion.
This value can be used to control costs for text generated via API.
This value is now deprecated in favor of
max_completion_tokens, and is not compatible with o1 series models.
- n? int? - How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep
nas1to minimize costs.
- prediction? OpenAIPredictionContent - Static predicted output content, such as the content of a text file that is being regenerated.
- seed? int? - This feature is in Beta.
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same
seedand parameters should return the same result. Determinism is not guaranteed, and you should refer to thesystem_fingerprintresponse parameter to monitor changes in the backend.
- stream_options? OpenAIChatCompletionStreamOptions - Options for streaming response. Only set this when you set
stream: true.
- tools? (OpenAIChatCompletionTool|OpenAICustomToolChatCompletions)[] - A list of tools the model may call. You can provide either custom tools or function tools.
- tool_choice? OpenAIChatCompletionToolChoiceOption - Controls which (if any) tool is called by the model.
nonemeans the model will not call any tool and instead generates a message.automeans the model can pick between generating a message or calling one or more tools.requiredmeans the model must call one or more tools. Specifying a particular tool via{"type": "function", "function": {"name": "my_function"}}forces the model to call that tool.noneis the default when no tools are present.autois the default if tools are present.
- parallel_tool_calls? boolean - Whether to enable parallel function calling during tool use.
- function_call? "none"|"auto"|OpenAIChatCompletionFunctionCallOption - Deprecated in favor of
tool_choice. Controls which (if any) function is called by the model.nonemeans the model will not call a function and instead generates a message.automeans the model can pick between generating a message or calling a function. Specifying a particular function via{"name": "my_function"}forces the model to call that function.noneis the default when no functions are present.autois the default if functions are present.
- functions? OpenAIChatCompletionFunctions[] - Deprecated in favor of
tools. A list of functions the model may generate JSON inputs for.
- user_security_context? AzureUserSecurityContext - User security context contains several parameters that describe the application itself, and the end user that interacts with the application. These fields assist your security operations teams to investigate and mitigate security incidents by providing a comprehensive approach to protecting your AI applications. Learn more about protecting AI applications using Microsoft Defender for Cloud.
azure.openai.chat: ConnectionConfig
Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint.
Fields
- auth BearerTokenConfig|ApiKeysConfig - Provides Auth configurations needed when communicating with a remote HTTP endpoint.
- httpVersion HttpVersion(default http:HTTP_2_0) - The HTTP version understood by the client
- http1Settings ClientHttp1Settings(default {}) - Configurations related to HTTP/1.x protocol
- http2Settings ClientHttp2Settings(default {}) - Configurations related to HTTP/2 protocol
- timeout decimal(default 30) - The maximum time to wait (in seconds) for a response before closing the connection
- forwarded string(default "disable") - The choice of setting
forwarded/x-forwardedheader
- followRedirects? FollowRedirects - Configurations associated with Redirection
- poolConfig? PoolConfiguration - Configurations associated with request pooling
- cache CacheConfig(default {}) - HTTP caching related configurations
- compression Compression(default http:COMPRESSION_AUTO) - Specifies the way of handling compression (
accept-encoding) header
- circuitBreaker? CircuitBreakerConfig - Configurations associated with the behaviour of the Circuit Breaker
- retryConfig? RetryConfig - Configurations associated with retrying
- cookieConfig? CookieConfig - Configurations associated with cookies
- responseLimits ResponseLimitConfigs(default {}) - Configurations associated with inbound response size limits
- secureSocket? ClientSecureSocket - SSL/TLS-related options
- proxy? ProxyConfig - Proxy server related options
- socketConfig ClientSocketConfig(default {}) - Provides settings related to client socket configuration
- validation boolean(default true) - Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
- laxDataBinding boolean(default true) - Enables relaxed data binding on the client side. When enabled,
nilvalues are treated as optional, and absent fields are handled asnilabletypes. Enabled by default.
azure.openai.chat: CreateChatCompletionQueries
Represents the Queries record for the operation: createChatCompletion
Fields
- api\-version? AzureAIFoundryModelsApiVersion - The explicit Azure AI Foundry Models API version to use for this request.
v1if not otherwise specified.
azure.openai.chat: InlineResponse200PromptFilterResults
Fields
- prompt_index Signed32 - The index of the input prompt that this content filter result corresponds to.
- content_filter_results AzureContentFilterResultForPrompt - The content filter results associated with the indexed input prompt.
azure.openai.chat: OpenAIChatCompletionAllowedTools
Constrains the tools available to the model to a pre-defined set.
Fields
- mode "auto"|"required" - Constrains the tools available to the model to a pre-defined set.
autoallows the model to pick from among the allowed tools and generate a message.requiredrequires the model to call one or more of the allowed tools.
- tools record {}[] - A list of tool definitions that the model should be allowed to call.
For the Chat Completions API, the list of tool definitions might look like:
[ { "type": "function", "function": { "name": "get_weather" } }, { "type": "function", "function": { "name": "get_time" } } ]
azure.openai.chat: OpenAIChatCompletionAllowedToolsChoice
Constrains the tools available to the model to a pre-defined set.
Fields
- 'type "allowed_tools" - Allowed tool configuration type. Always
allowed_tools.
- allowed_tools OpenAIChatCompletionAllowedTools - Constrains the tools available to the model to a pre-defined set.
azure.openai.chat: OpenAIChatCompletionFunctionCallOption
Specifying a particular function via {"name": "my_function"} forces the model to call that function.
Fields
- name string - The name of the function to call.
azure.openai.chat: OpenAIChatCompletionFunctions
Fields
- description? string - A description of what the function does, used by the model to choose when and how to call the function.
- name string - The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
- parameters? OpenAIFunctionParameters - The parameters the functions accepts, described as a JSON Schema object.
See the JSON Schema reference
for documentation about the format.
Omitting
parametersdefines a function with an empty parameter list.
azure.openai.chat: OpenAIChatCompletionMessageCustomToolCall
A call to a custom tool created by the model.
Fields
- id string - The ID of the tool call.
- 'type "custom" - The type of the tool. Always
custom.
- custom OpenAIChatCompletionMessageCustomToolCallCustom - The custom tool that the model called.
azure.openai.chat: OpenAIChatCompletionMessageCustomToolCallCustom
Fields
- name string -
- input string -
azure.openai.chat: OpenAIChatCompletionMessageToolCall
A call to a function tool created by the model.
Fields
- id string - The ID of the tool call.
- 'type "function" - The type of the tool. Currently, only
functionis supported.
- 'function OpenAIChatCompletionMessageToolCallFunction - The function that the model called.
azure.openai.chat: OpenAIChatCompletionMessageToolCallChunk
Fields
- index int -
- id? string - The ID of the tool call.
- 'type? "function" - The type of the tool. Currently, only
functionis supported.
- 'function? OpenAIChatCompletionMessageToolCallChunkFunction -
azure.openai.chat: OpenAIChatCompletionMessageToolCallChunkFunction
Fields
- name? string -
- arguments? string -
azure.openai.chat: OpenAIChatCompletionMessageToolCallFunction
Fields
- name string -
- arguments string -
azure.openai.chat: OpenAIChatCompletionNamedToolChoice
Specifies a tool the model should use. Use to force the model to call a specific function.
Fields
- 'type "function" - For function calling, the type is always
function.
- 'function OpenAIChatCompletionNamedToolChoiceFunction -
azure.openai.chat: OpenAIChatCompletionNamedToolChoiceCustom
Specifies a tool the model should use. Use to force the model to call a specific custom tool.
Fields
- 'type "custom" - For custom tool calling, the type is always
custom.
azure.openai.chat: OpenAIChatCompletionNamedToolChoiceCustomCustom
Fields
- name string -
azure.openai.chat: OpenAIChatCompletionNamedToolChoiceFunction
Fields
- name string -
azure.openai.chat: OpenAIChatCompletionRequestMessage
Fields
azure.openai.chat: OpenAIChatCompletionRequestMessageContentPartText
Fields
- 'type "text" - The type of the content part.
- text string - The text content.
azure.openai.chat: OpenAIChatCompletionResponseMessage
If the audio output modality is requested, this object contains data about the audio response from the model.
Fields
- content string? -
- refusal string? -
- tool_calls? OpenAIChatCompletionMessageToolCallsItem - The tool calls generated by the model, such as function calls.
- annotations? OpenAIChatCompletionResponseMessageAnnotations[] - Annotations for the message, when applicable, as when using the web search tool.
- role "assistant" - The role of the author of this message.
- function_call? OpenAIChatCompletionResponseMessageFunctionCall - Deprecated and replaced by
tool_calls. The name and arguments of a function that should be called, as generated by the model.
- reasoning_content? string - An Azure-specific extension property containing generated reasoning content from supported models.
azure.openai.chat: OpenAIChatCompletionResponseMessageAnnotations
Fields
- 'type "url_citation" -
- url_citation OpenAIChatCompletionResponseMessageAnnotationsUrlCitation -
azure.openai.chat: OpenAIChatCompletionResponseMessageAnnotationsUrlCitation
Fields
- end_index int -
- start_index int -
- url string -
- title string -
azure.openai.chat: OpenAIChatCompletionResponseMessageAudio
Fields
- id string -
- expires_at int -
- data string -
- transcript string -
azure.openai.chat: OpenAIChatCompletionResponseMessageFunctionCall
Fields
- arguments string -
- name string -
azure.openai.chat: OpenAIChatCompletionStreamOptions
Options for streaming response. Only set this when you set stream: true.
Fields
- include_usage? boolean - If set, an additional chunk will be streamed before the
data: [DONE]message. Theusagefield on this chunk shows the token usage statistics for the entire request, and thechoicesfield will always be an empty array. All other chunks will also include ausagefield, but with a null value. NOTE: If the stream is interrupted, you may not receive the final usage chunk which contains the total token usage for the request.
- include_obfuscation? boolean - When true, stream obfuscation will be enabled. Stream obfuscation adds
random characters to an
obfuscationfield on streaming delta events to normalize payload sizes as a mitigation to certain side-channel attacks. These obfuscation fields are included by default, but add a small amount of overhead to the data stream. You can setinclude_obfuscationto false to optimize for bandwidth if you trust the network links between your application and the OpenAI API.
azure.openai.chat: OpenAIChatCompletionStreamResponseDelta
A chat completion delta generated by streamed model responses.
Fields
- content? string? -
- function_call? OpenAIChatCompletionStreamResponseDeltaFunctionCall - Deprecated and replaced by
tool_calls. The name and arguments of a function that should be called, as generated by the model.
- tool_calls? OpenAIChatCompletionMessageToolCallChunk[] -
- role? "developer"|"system"|"user"|"assistant"|"tool" - The role of the author of this message.
- refusal? string? -
- reasoning_content? string - An Azure-specific extension property containing generated reasoning content from supported models.
azure.openai.chat: OpenAIChatCompletionStreamResponseDeltaFunctionCall
Fields
- arguments? string -
- name? string -
azure.openai.chat: OpenAIChatCompletionTokenLogprob
Fields
- token string - The token.
- logprob decimal - The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value
-9999.0is used to signify that the token is very unlikely.
- bytes int[]? -
- top_logprobs OpenAIChatCompletionTokenLogprobTopLogprobs[] - List of the most likely tokens and their log probability, at this token position. The number of entries may be fewer than the requested
top_logprobs.
azure.openai.chat: OpenAIChatCompletionTokenLogprobTopLogprobs
Fields
- token string -
- logprob decimal -
- bytes int[]? -
azure.openai.chat: OpenAIChatCompletionTool
A function tool that can be used to generate a response.
Fields
- 'type "function" - The type of the tool. Currently, only
functionis supported.
- 'function OpenAIFunctionObject -
azure.openai.chat: OpenAICompletionUsage
Usage statistics for the completion request.
Fields
- completion_tokens int - Number of tokens in the generated completion.
- prompt_tokens int - Number of tokens in the prompt.
- total_tokens int - Total number of tokens used in the request (prompt + completion).
- completion_tokens_details? OpenAICompletionUsageCompletionTokensDetails - Breakdown of tokens used in a completion.
- prompt_tokens_details? OpenAICompletionUsagePromptTokensDetails - Breakdown of tokens used in the prompt.
azure.openai.chat: OpenAICompletionUsageCompletionTokensDetails
Fields
- accepted_prediction_tokens? int -
- audio_tokens? int -
- reasoning_tokens? int -
- rejected_prediction_tokens? int -
azure.openai.chat: OpenAICompletionUsagePromptTokensDetails
Fields
- audio_tokens? int -
- cached_tokens? int -
azure.openai.chat: OpenAICreateChatCompletionRequestAudio
Fields
- voice OpenAIVoiceIdsOrCustomVoice - A built-in voice name or a custom voice reference.
- format "wav"|"aac"|"mp3"|"flac"|"opus"|"pcm16" -
azure.openai.chat: OpenAICreateChatCompletionRequestResponseFormat
An object specifying the format that the model must output.
Setting to { "type": "json_schema", "json_schema": {...} } enables
Structured Outputs which ensures the model will match your supplied JSON
schema. Learn more in the Structured Outputs
guide.
Setting to { "type": "json_object" } enables the older JSON mode, which
ensures the message the model generates is valid JSON. Using json_schema
is preferred for models that support it.
Fields
azure.openai.chat: OpenAICreateChatCompletionResponseChoices
Fields
- finish_reason "stop"|"length"|"tool_calls"|"content_filter"|"function_call" -
- index int -
- message OpenAIChatCompletionResponseMessage - If the audio output modality is requested, this object contains data about the audio response from the model.
- content_filter_results? AzureContentFilterResultForChoice - A content filter result for a single response item produced by a generative AI system.
azure.openai.chat: OpenAICreateChatCompletionResponseChoicesLogprobs
Fields
- content OpenAIChatCompletionTokenLogprob[]? -
- refusal OpenAIChatCompletionTokenLogprob[]? -
azure.openai.chat: OpenAICreateChatCompletionStreamResponseChoices
Fields
- delta OpenAIChatCompletionStreamResponseDelta - A chat completion delta generated by streamed model responses.
- finish_reason "stop"|"length"|"tool_calls"|"content_filter"|"function_call"? -
- index int -
azure.openai.chat: OpenAICreateChatCompletionStreamResponseChoicesLogprobs
Fields
- content OpenAIChatCompletionTokenLogprob[]? -
- refusal OpenAIChatCompletionTokenLogprob[]? -
azure.openai.chat: OpenAICustomToolChatCompletions
A custom tool that processes input using a specified format.
Fields
- 'type "custom" - The type of the custom tool. Always
custom.
- custom OpenAICustomToolChatCompletionsCustom - Properties of the custom tool.
azure.openai.chat: OpenAICustomToolChatCompletionsCustom
Fields
- name string -
- description? string -
azure.openai.chat: OpenAICustomToolChatCompletionsCustomFormatGrammar
Fields
- 'type "grammar" -
azure.openai.chat: OpenAICustomToolChatCompletionsCustomFormatGrammarGrammar
Fields
- definition string -
- syntax "lark"|"regex" -
azure.openai.chat: OpenAICustomToolChatCompletionsCustomFormatText
Fields
- 'type "text" -
azure.openai.chat: OpenAIFunctionObject
Fields
- description? string - A description of what the function does, used by the model to choose when and how to call the function.
- name string - The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
- parameters? OpenAIFunctionParameters - The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
Omitting
parametersdefines a function with an empty parameter list.
- strict? boolean? -
azure.openai.chat: OpenAIFunctionParameters
The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
Omitting parameters defines a function with an empty parameter list.
azure.openai.chat: OpenAIMetadata
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
azure.openai.chat: OpenAIPredictionContent
Static predicted output content, such as the content of a text file that is being regenerated.
Fields
- 'type "content" - The type of the predicted content you want to provide. This type is
currently always
content.
- content string|OpenAIChatCompletionRequestMessageContentPartText[] - The content that should be matched when generating a model response. If generated tokens would match this content, the entire model response can be returned much more quickly.
Union types
azure.openai.chat: AzureAIFoundryModelsApiVersion
AzureAIFoundryModelsApiVersion
azure.openai.chat: OpenAIStopConfiguration
OpenAIStopConfiguration
Not supported with latest reasoning models o3 and o4-mini.
Up to 4 sequences where the API will stop generating further tokens. The
returned text will not contain the stop sequence.
azure.openai.chat: OpenAIReasoningEffort
OpenAIReasoningEffort
Constrains effort on reasoning for
reasoning models.
Currently supported values are none, minimal, low, medium, high, and xhigh. Reducing
reasoning effort can result in faster responses and fewer tokens used
on reasoning in a response.
gpt-5.1defaults tonone, which does not perform reasoning. The supported reasoning values forgpt-5.1arenone,low,medium, andhigh. Tool calls are supported for all reasoning values in gpt-5.1.- All models before
gpt-5.1default tomediumreasoning effort, and do not supportnone. - The
gpt-5-promodel defaults to (and only supports)highreasoning effort. xhighis supported for all models aftergpt-5.1-codex-max.
azure.openai.chat: OpenAIVerbosity
OpenAIVerbosity
Constrains the verbosity of the model's response. Lower values will result in
more concise responses, while higher values will result in more verbose responses.
Currently supported values are low, medium, and high.
azure.openai.chat: OpenAIVoiceIdsOrCustomVoice
OpenAIVoiceIdsOrCustomVoice
A built-in voice name or a custom voice reference.
azure.openai.chat: InlineResponse200
InlineResponse200
azure.openai.chat: OpenAICreateChatCompletionRequestResponseFormatType
OpenAICreateChatCompletionRequestResponseFormatType
azure.openai.chat: OpenAIChatCompletionToolChoiceOption
OpenAIChatCompletionToolChoiceOption
Controls which (if any) tool is called by the model.
none means the model will not call any tool and instead generates a message.
auto means the model can pick between generating a message or calling one or more tools.
required means the model must call one or more tools.
Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool.
none is the default when no tools are present. auto is the default if tools are present.
azure.openai.chat: OpenAIVoiceIdsShared
OpenAIVoiceIdsShared
azure.openai.chat: OpenAIChatCompletionRequestMessageType
OpenAIChatCompletionRequestMessageType
Array types
azure.openai.chat: OpenAIResponseModalities
OpenAIResponseModalities
Output types that you would like the model to generate.
Most models are capable of generating text, which is the default:
["text"]
The gpt-4o-audio-preview model can also be used to
generate audio. To request that this model generate
both text and audio responses, you can use:
["text", "audio"]
azure.openai.chat: OpenAIChatCompletionMessageToolCallsItem
OpenAIChatCompletionMessageToolCallsItem
The tool calls generated by the model, such as function calls.
Simple name reference types
azure.openai.chat: AzureContentFilterPersonallyIdentifiableInformationResult
AzureContentFilterPersonallyIdentifiableInformationResult
A content filter detection result for Personally Identifiable Information that includes harm extensions.
Import
import ballerinax/azure.openai.chat;Metadata
Released date: about 13 hours ago
Version: 4.0.0
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: 2201.12.0
GraalVM compatible: Yes
Pull count
Total: 25638
Current verison: 9
Weekly downloads
Keywords
AI/Chat
Azure
Azure OpenAI
Chat Completions
Vendor/Microsoft
Contributors