CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/maven-org-springframework-ai--spring-ai-azure-openai

Spring AI integration for Azure OpenAI services providing chat completion, text embeddings, image generation, and audio transcription with GPT, DALL-E, and Whisper models

Overview
Eval results
Files

Spring AI Azure OpenAI

Spring AI Azure OpenAI provides integration between Spring AI and Azure OpenAI services. It implements Spring AI's model interfaces for chat completion, text embeddings, image generation, and audio transcription using Azure's OpenAI platform.

Package Information

  • Package Name: org.springframework.ai:spring-ai-azure-openai
  • Package Type: Maven
  • Language: Java
  • Version: 1.1.2

Installation:

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-azure-openai</artifactId>
    <version>1.1.2</version>
</dependency>

Quick Start

See Quick Start Guide for step-by-step setup instructions.

Core Capabilities

This package provides four main AI model implementations:

CapabilityModel ClassUse Case
Chat CompletionAzureOpenAiChatModelConversational AI with GPT models
Text EmbeddingsAzureOpenAiEmbeddingModelVector embeddings for semantic search
Image GenerationAzureOpenAiImageModelImage creation with DALL-E
Audio TranscriptionAzureOpenAiAudioTranscriptionModelSpeech-to-text with Whisper

All models support:

  • Spring Boot autoconfiguration
  • Micrometer observability
  • Reactive streaming (where applicable)
  • Thread-safe concurrent operations

API Overview

Chat Completion

class AzureOpenAiChatModel implements ChatModel {
    ChatResponse call(Prompt prompt);
    Flux<ChatResponse> stream(Prompt prompt);
}

Key Features: Synchronous/streaming responses, tool calling, structured outputs, JSON schema support

Supported Models: gpt-4o, gpt-4, gpt-35-turbo, o1, o3, o4-mini

Full Chat API Reference

Text Embeddings

class AzureOpenAiEmbeddingModel extends AbstractEmbeddingModel {
    EmbeddingResponse call(EmbeddingRequest request);
    float[] embed(Document document);
}

Key Features: Configurable dimensions, batch processing, metadata handling

Supported Models: text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large

Full Embeddings API Reference

Image Generation

class AzureOpenAiImageModel implements ImageModel {
    ImageResponse call(ImagePrompt prompt);
}

Key Features: DALL-E 2/3 support, size/quality/style controls, multiple formats

Supported Models: dall-e-3, dall-e-2

Full Image API Reference

Audio Transcription

class AzureOpenAiAudioTranscriptionModel implements TranscriptionModel {
    AudioTranscriptionResponse call(AudioTranscriptionPrompt prompt);
    String call(Resource audioResource);
}

Key Features: Multiple formats (JSON, SRT, VTT), timestamps, language detection

Supported Models: whisper

Full Audio API Reference

Configuration

Azure OpenAI Client

All models require an OpenAIClient:

OpenAIClient client = new OpenAIClientBuilder()
    .credential(new AzureKeyCredential(apiKey))
    .endpoint(endpoint)
    .buildClient();

Deployment Names

Azure OpenAI uses deployment names instead of model names:

TypeExample Deployments
Chatgpt-4o, gpt-4, gpt-35-turbo, o1, o3
Embeddingstext-embedding-ada-002, text-embedding-3-small
Imagesdall-e-3, dall-e-2
Audiowhisper

Common Patterns

Builder Pattern:

AzureOpenAiChatModel chatModel = AzureOpenAiChatModel.builder()
    .openAIClientBuilder(clientBuilder)
    .defaultOptions(options)
    .observationRegistry(observationRegistry)
    .build();

Options Configuration:

AzureOpenAiChatOptions options = AzureOpenAiChatOptions.builder()
    .deploymentName("gpt-4o")
    .temperature(0.7)
    .maxTokens(1000)
    .build();

Thread Safety

All model classes are fully thread-safe and can handle concurrent requests. Create one instance and reuse it across your application.

Documentation Structure

Guides

Examples

Reference

Quick Reference Tables

Chat Model Parameters

ParameterRangeDefaultDescription
temperature0.0-2.00.7Randomness control
maxTokens> 0-Total token limit (standard models)
maxCompletionTokens> 0-Completion limit (reasoning models)
topP0.0-1.01.0Nucleus sampling
frequencyPenalty-2.0-2.00.0Repetition penalty
presencePenalty-2.0-2.00.0Topic diversity

Embedding Model Dimensions

ModelDefaultConfigurableMax Input
text-embedding-ada-0021536No8191 tokens
text-embedding-3-small1536Yes (up to 1536)8191 tokens
text-embedding-3-large3072Yes (up to 3072)8191 tokens

Image Model Sizes

ModelSupported Sizes
DALL-E 31024×1024, 1792×1024, 1024×1792
DALL-E 2256×256, 512×512, 1024×1024

Audio Formats

FormatExtensionQualityUse Case
mp3.mp3GoodGeneral purpose
wav.wavExcellentBest quality
m4a.m4aGoodMobile recordings
webm.webmGoodWeb recordings

File Limit: 25 MB maximum

Common Imports

// Chat
import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
import org.springframework.ai.azure.openai.AzureOpenAiChatOptions;

// Embeddings
import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingModel;
import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingOptions;

// Images
import org.springframework.ai.azure.openai.AzureOpenAiImageModel;
import org.springframework.ai.azure.openai.AzureOpenAiImageOptions;

// Audio
import org.springframework.ai.azure.openai.AzureOpenAiAudioTranscriptionModel;
import org.springframework.ai.azure.openai.AzureOpenAiAudioTranscriptionOptions;

// Azure Client
import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.core.credential.AzureKeyCredential;

Utility Classes

MergeUtils

Utility for merging chat completion responses in streaming scenarios.

class MergeUtils {
    static ChatCompletions emptyChatCompletions();
    static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCompletions right);
}

AzureOpenAiRuntimeHints

Provides GraalVM native image compilation hints. Automatically detected by Spring AOT - no manual configuration needed.

class AzureOpenAiRuntimeHints implements RuntimeHintsRegistrar {
    void registerHints(RuntimeHints hints, ClassLoader classLoader);
}

Package Organization

org.springframework.ai.azure.openai
├── AzureOpenAiChatModel
├── AzureOpenAiChatOptions
├── AzureOpenAiResponseFormat
├── AzureOpenAiEmbeddingModel
├── AzureOpenAiEmbeddingOptions
├── AzureOpenAiImageModel
├── AzureOpenAiImageOptions
├── AzureOpenAiAudioTranscriptionModel
├── AzureOpenAiAudioTranscriptionOptions
├── MergeUtils
├── metadata/
│   ├── AzureOpenAiAudioTranscriptionResponseMetadata
│   ├── AzureOpenAiImageGenerationMetadata
│   └── AzureOpenAiImageResponseMetadata
└── aot/
    └── AzureOpenAiRuntimeHints

Next Steps

  1. Get Started: Follow the Quick Start Guide
  2. Explore Examples: Check Real-World Scenarios
  3. Deep Dive: Read the API References for detailed documentation
  4. Troubleshoot: See Error Handling Guide for common issues
tessl i tessl/maven-org-springframework-ai--spring-ai-azure-openai@1.1.1
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework.ai/spring-ai-azure-openai@1.1.x