Skip to content

Commit ffffb0b

Browse files
authored
Support Gate proxy authentication via ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL (#1096)
When running inside Alcove, Gate proxies all LLM traffic and injects real credentials. This change lets agent-splunk use that flow by reading ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL to send requests through Gate instead of authenticating directly to Vertex AI. Also adds CLAUDE_MODEL env var to control the default model, and VERTEX_SA_JSON for direct Vertex AI auth via service account JSON. Three auth modes are now supported: - Proxy: ANTHROPIC_API_KEY + ANTHROPIC_BASE_URL (Alcove/Gate) - Service account: VERTEX_SA_JSON (direct Vertex AI) - ADC: ANTHROPIC_VERTEX_PROJECT_ID (original behavior) Assisted By: claude-opus-4.6
1 parent f9c2c0f commit ffffb0b

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

tools/agents/agent-splunk/main.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@ func run() error {
3131
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
3232
defer stop()
3333

34+
// Auth mode 1: Proxy (ANTHROPIC_API_KEY + ANTHROPIC_BASE_URL).
35+
// Gate handles real credentials; the agent sends requests to the proxy.
36+
apiKey := os.Getenv("ANTHROPIC_API_KEY")
37+
baseURL := os.Getenv("ANTHROPIC_BASE_URL")
38+
39+
// Auth mode 2: Service account JSON for direct Vertex AI access.
3440
var saCredential []byte
3541
if saJSON := os.Getenv("VERTEX_SA_JSON"); saJSON != "" {
3642
saCredential = []byte(saJSON)
3743
fmt.Fprintf(os.Stderr, "[auth] using VERTEX_SA_JSON for Vertex AI authentication\n")
3844
}
3945

46+
// Resolve project ID (required for Vertex AI modes, not for proxy mode).
4047
projectID := os.Getenv("ANTHROPIC_VERTEX_PROJECT_ID")
4148
if projectID == "" && len(saCredential) > 0 {
4249
var sa struct {
@@ -50,16 +57,26 @@ func run() error {
5057
}
5158
projectID = sa.ProjectID
5259
}
53-
if projectID == "" {
54-
return fmt.Errorf("ANTHROPIC_VERTEX_PROJECT_ID environment variable is required (or set VERTEX_SA_JSON with a service account that contains project_id)")
60+
61+
if apiKey == "" && projectID == "" {
62+
return fmt.Errorf("set ANTHROPIC_API_KEY (proxy mode) or ANTHROPIC_VERTEX_PROJECT_ID / VERTEX_SA_JSON (Vertex AI mode)")
63+
}
64+
65+
if apiKey != "" {
66+
fmt.Fprintf(os.Stderr, "[auth] using proxy mode (ANTHROPIC_BASE_URL=%s)\n", baseURL)
5567
}
5668

5769
region := os.Getenv("CLOUD_ML_REGION")
5870
if region == "" {
5971
region = "us-east5"
6072
}
6173

62-
inputModel := flag.String("model", "claude-opus-4-6", "Define the model (claude-opus-4-6,gemini-2.5-pro). Default: claude-opus-4-6")
74+
defaultModel := "claude-opus-4-6"
75+
if envModel := os.Getenv("CLAUDE_MODEL"); envModel != "" {
76+
defaultModel = envModel
77+
}
78+
79+
inputModel := flag.String("model", defaultModel, fmt.Sprintf("Define the model (claude-opus-4-6,gemini-2.5-pro). Default: %s", defaultModel))
6380
inputQuestion := flag.String("question", "", "Question to ask the model")
6481
flag.Parse()
6582

@@ -120,6 +137,8 @@ func run() error {
120137
ProjectID: projectID,
121138
Region: region,
122139
SACredential: saCredential,
140+
APIKey: apiKey,
141+
BaseURL: baseURL,
123142
}
124143
case "gemini-2.5-pro":
125144
model = models.Gemini{

tools/agents/agent-splunk/models/anthropic.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,32 @@ type Claude struct {
1414
ProjectID string
1515
Region string
1616
SACredential []byte
17+
APIKey string
18+
BaseURL string
1719
}
1820

1921
func (claude Claude) ModelRun(ctx context.Context, cfg RunConfig) (string, error) {
22+
var opts []anthropic.Option
23+
opts = append(opts, anthropic.WithModel(claude.Model))
2024

21-
// Claude via Vertex AI.
22-
llm, err := anthropic.New(
23-
anthropic.WithModel(claude.Model),
24-
anthropic.WithToken("vertex-ai"),
25-
anthropic.WithHTTPClient(&anthropicClient.VertexClient{
26-
ProjectID: claude.ProjectID,
27-
Region: claude.Region,
28-
Model: claude.Model,
29-
SACredential: claude.SACredential,
30-
}),
31-
)
25+
if claude.APIKey != "" {
26+
opts = append(opts, anthropic.WithToken(claude.APIKey))
27+
if claude.BaseURL != "" {
28+
opts = append(opts, anthropic.WithBaseURL(claude.BaseURL))
29+
}
30+
} else {
31+
opts = append(opts,
32+
anthropic.WithToken("vertex-ai"),
33+
anthropic.WithHTTPClient(&anthropicClient.VertexClient{
34+
ProjectID: claude.ProjectID,
35+
Region: claude.Region,
36+
Model: claude.Model,
37+
SACredential: claude.SACredential,
38+
}),
39+
)
40+
}
41+
42+
llm, err := anthropic.New(opts...)
3243
if err != nil {
3344
return "", fmt.Errorf("init anthropic client: %w", err)
3445
}

0 commit comments

Comments
 (0)