Skip to content

Commit 58ab6cd

Browse files
authored
provider/openai: Allow custom token key (#87)
This makes it possible to use other OpenAI-compatible APIs. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 5a83479 commit 58ab6cd

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pkg/config/v1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type ModelConfig struct {
9393
BaseURL string `json:"base_url,omitempty" yaml:"base_url,omitempty"`
9494
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty" yaml:"parallel_tool_calls,omitempty"`
9595
Env map[string]string `json:"env,omitempty" yaml:"env,omitempty"`
96+
TokenKey string `json:"token_key,omitempty" yaml:"token_key,omitempty"`
9697
}
9798

9899
// Config represents the entire configuration file

pkg/model/provider/openai/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
4747

4848
var openaiConfig openai.ClientConfig
4949
if gateway := globalOptions.Gateway(); gateway == "" {
50-
authToken, err := env.Get(ctx, "OPENAI_API_KEY")
50+
key := cfg.TokenKey
51+
if key == "" {
52+
key = "OPENAI_API_KEY"
53+
}
54+
authToken, err := env.Get(ctx, key)
5155
if err != nil || authToken == "" {
5256
slog.Error("OpenAI client creation failed", "error", "failed to get authentication token", "details", err)
5357
return nil, errors.New("OPENAI_API_KEY environment variable is required")

0 commit comments

Comments
 (0)