@@ -18,6 +18,8 @@ import (
1818 "github.com/google/uuid"
1919 "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
2020 "github.com/wavetermdev/waveterm/pkg/util/utilfn"
21+ "github.com/wavetermdev/waveterm/pkg/waveobj"
22+ "github.com/wavetermdev/waveterm/pkg/wstore"
2123)
2224
2325// these conversions are based off the anthropic spec
@@ -26,19 +28,15 @@ import (
2628// buildAnthropicHTTPRequest creates a complete HTTP request for the Anthropic API
2729func buildAnthropicHTTPRequest (ctx context.Context , msgs []anthropicInputMessage , chatOpts uctypes.WaveChatOpts ) (* http.Request , error ) {
2830 opts := chatOpts .Config
29- if opts .APIToken == "" {
30- return nil , errors .New ("Anthropic API token missing" )
31- }
3231 if opts .Model == "" {
3332 return nil , errors .New ("opts.model is required" )
3433 }
3534
3635 // Set defaults
37- baseURL := opts .BaseURL
38- if baseURL == "" {
39- baseURL = AnthropicDefaultBaseURL
36+ endpoint := opts .BaseURL
37+ if endpoint == "" {
38+ endpoint = AnthropicDefaultBaseURL
4039 }
41- endpoint := strings .TrimRight (baseURL , "/" ) + "/v1/messages"
4240
4341 apiVersion := opts .APIVersion
4442 if apiVersion == "" {
@@ -120,6 +118,10 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage
120118 }
121119 log .Printf ("tools: %s\n " , strings .Join (toolNames , ", " ))
122120 log .Printf ("anthropicMsgs JSON:\n %s" , jsonStr )
121+ log .Printf ("has-api-key: %v\n " , opts .APIToken != "" )
122+ if endpoint != AnthropicDefaultBaseURL {
123+ log .Printf ("baseurl: %s\n " , endpoint )
124+ }
123125 }
124126
125127 var buf bytes.Buffer
@@ -133,11 +135,19 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage
133135 if err != nil {
134136 return nil , err
135137 }
138+ client , err := wstore.DBGetSingleton [* waveobj.Client ](ctx )
139+ if err != nil {
140+ return nil , fmt .Errorf ("error getting client for Wave AI request: %w" , err )
141+ }
136142
137143 req .Header .Set ("content-type" , "application/json" )
138- req .Header .Set ("x-api-key" , opts .APIToken )
144+ if opts .APIToken != "" {
145+ req .Header .Set ("x-api-key" , opts .APIToken )
146+ }
139147 req .Header .Set ("anthropic-version" , apiVersion )
140148 req .Header .Set ("accept" , "text/event-stream" )
149+ req .Header .Set ("X-Wave-ClientId" , client .OID )
150+ req .Header .Set ("X-Wave-APIType" , "anthropic" )
141151
142152 return req , nil
143153}
0 commit comments