Refactor API providers
Author: sashabaranovCreated Apr 24, 2024Updated Nov 19, 2025
Labelsenhancementhelp wanted
We have a growing number of different API providers: OpenAI, Azure, Cloudflare Getaway. At the same time other tools keep adding their OpenAI-compatible APIs (e.g. Ollama).
Considering #693, here's a sketch of how we can add new API providers painlessly:
type apiProvider interface { // might want to expose that
SetAuthForRequest(req *http.Request)
GetFullURL(suffix string, args ...any) // Shouldn't be `any`, but a type-safe list like requestOption
}
type APIProviderConfig interface {
// whatever we need here
}client usage:
config := openai.DefaultConfigWithAPIProvider(
openai.AzureOpenAIProviderConfig("your Azure OpenAI Key", "https://your Azure OpenAI Endpoint"),
)
client := openai.NewClientWithConfig(config)
Source: sashabaranov/go-openai