Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type API struct {
APIKey string `yaml:"api-key"`
APIKeyEnv string `yaml:"api-key-env"`
APIKeyCmd string `yaml:"api-key-cmd"`
Version string `yaml:"version"` // XXX: not used anywhere
Version string `yaml:"version"`
BaseURL string `yaml:"base-url"`
Models map[string]Model `yaml:"models"`
User string `yaml:"user"`
Expand Down
3 changes: 2 additions & 1 deletion config_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ apis:
azure:
# Set to 'azure-ad' to use Active Directory
# Azure OpenAI setup: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource
base-url: https://YOUR_RESOURCE_NAME.openai.azure.com
base-url: https://YOUR_RESOURCE_NAME.cognitiveservices.azure.com
api-key:
api-key-env: AZURE_OPENAI_KEY
version:
models:
gpt-4:
aliases: ["az4"]
Expand Down
7 changes: 4 additions & 3 deletions internal/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type Config struct {
HTTPClient interface {
Do(*http.Request) (*http.Response, error)
}
APIType string
APIType string
APIVersion string
}

// DefaultConfig returns the default configuration for the OpenAI API client.
Expand All @@ -47,10 +48,10 @@ func New(config Config) *Client {
opts = append(opts, option.WithHTTPClient(config.HTTPClient))
}

if config.APIType == "azure-ad" {
if config.APIType == "azure" {
opts = append(opts, azure.WithAPIKey(config.AuthToken))
if config.BaseURL != "" {
opts = append(opts, azure.WithEndpoint(config.BaseURL, "v1"))
opts = append(opts, azure.WithEndpoint(config.BaseURL, config.APIVersion))
}
} else {
opts = append(opts, option.WithAPIKey(config.AuthToken))
Expand Down
11 changes: 5 additions & 6 deletions mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,16 @@ func (m *Mods) startCompletionCmd(content string) tea.Cmd {
if api.BaseURL != "" {
ccfg.BaseURL = api.BaseURL
}
case "azure", "azure-ad": //nolint:goconst
case "azure": //nolint:goconst
key, err := m.ensureKey(api, "AZURE_OPENAI_KEY", "https://aka.ms/oai/access")
if err != nil {
return modsError{err, "Azure authentication failed"}
}
ccfg = openai.Config{
AuthToken: key,
BaseURL: api.BaseURL,
}
if mod.API == "azure-ad" {
ccfg.APIType = "azure-ad"
AuthToken: key,
BaseURL: api.BaseURL,
APIVersion: api.Version,
APIType: mod.API,
}
if api.User != "" {
cfg.User = api.User
Expand Down