chatopenaiazure

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 7 Imported by: 0

README

chat-openai-azure

Azure OpenAI backend for gitlab.com/phpboyscout/go/chat, part of the phpboyscout Go toolkit.

Azure serves OpenAI's models, so this module implements no protocol. It delegates to chat-openai and supplies the three things Azure addresses differently.

Why it is not openai-compatible

chat.ProviderOpenAICompatible reaches anything speaking the OpenAI wire protocol at a different base URL, such as Ollama. Azure does not qualify:

  • the model is addressed as a deployment name in the request path, not a model field;
  • an api-version query parameter is required on every request;
  • authentication is an api-key header or an Entra ID token, not Authorization: Bearer.

Point BaseURL at an Azure endpoint under another provider name and you get 404s that do not explain themselves.

Why it is a separate module

The Azure SDK's azcore is 33 packages. Folding Azure support into chat-openai would put them in the dependency graph of everyone talking to OpenAI, whether or not they ever address a deployment. So this module carries them and chat-openai does not, which depfootprint_test.go asserts from both sides.

It depends on azcore, the credential interface, and deliberately not on azidentity, the credential implementations, which is a further 48 packages.

Use

import (
    "gitlab.com/phpboyscout/go/chat"
    _ "gitlab.com/phpboyscout/go/chat-openai-azure"
)

client, err := chat.New(ctx, chat.Settings{Config: chat.Config{
    Provider:   chat.ProviderAzureOpenAI,
    BaseURL:    "https://my-resource.openai.azure.com",
    APIVersion: "2024-10-21",
    Model:      "my-deployment-name", // the deployment, not the model
    Token:      os.Getenv("AZURE_OPENAI_API_KEY"),
}})

Config.Model is the deployment name, which is whatever you called it in Azure and is frequently not the model's name. The SDK substitutes it into the request path.

Config.APIVersion is required and has no default. Azure's api-version strings are dated and models appear and disappear between them, so a default shipped here would be correct today and silently wrong later, surfacing as a missing model rather than as a version problem.

Entra ID instead of an api-key
import chatazure "gitlab.com/phpboyscout/go/chat-openai-azure"

client, err := chatazure.New(ctx, settings, chatazure.WithTokenCredential(cred))

cred is any azcore.TokenCredential. This module takes one rather than resolving one, so it does not depend on azidentity. For ambient discovery, bring azureclient and pass what it yields.

Set one credential or the other. Both together is refused at construction, as is neither.

What it reports

Capability lookup answers Unknown for anything model-dependent. A deployment name resolves to no model, and guessing from a substring would be a confident claim about somebody else's deployment. What the adapter implements (streaming, tools, structured output, and the rest) is reported normally.

Documentation

The family's documentation lives in the chat docs. The decisions behind this module are spec 0019.

Licence

MIT. See LICENSE.

Documentation

Overview

Package chatopenaiazure reaches Azure OpenAI deployments through the gitlab.com/phpboyscout/go/chat interface.

Azure serves OpenAI's models, so this module implements no protocol. It delegates to gitlab.com/phpboyscout/go/chat-openai and supplies the three things Azure addresses differently: the deployment name in the request path, an api-version on every request, and an api-key header or an Entra ID token instead of a bearer token.

It is a separate module rather than a construction path inside chat-openai because the Azure SDK's azcore is 33 packages, and folding it in would put them in the dependency graph of every consumer talking to OpenAI, whether or not they ever address a deployment. See https://gitlab.com/phpboyscout/go/chat/-/wikis/specs/0019-azure-openai-backend D2.

Activate it with a blank import, as with every provider in this family:

import _ "gitlab.com/phpboyscout/go/chat-openai-azure"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, settings chat.Settings, opts ...Option) (chat.ChatClient, error)

New builds an Azure OpenAI client, accepting options this provider owns. Reach for it when you need one; otherwise chat.New with the provider name is the ordinary path.

Types

type Option

type Option func(*options)

Option configures an Azure client at construction.

func WithTokenCredential

func WithTokenCredential(cred azcore.TokenCredential) Option

WithTokenCredential authenticates with Entra ID rather than an api-key.

It takes the credential rather than resolving one, so this module depends on azcore's interface and not on azidentity's implementations, which are a further 48 packages. A caller wanting ambient discovery passes azureclient.Ambient()'s credential in, which is one line where they already compose their dependencies. See spec 0019 D7.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL