@@ -90,10 +90,9 @@ func (p *Provider) SetBaseURL(url string) {
9090 p .client .SetBaseURL (url )
9191}
9292
93- func (p * Provider ) setBatchResultEndpoints (batchID string , endpoints map [string ]string ) {
94- batchID = strings .TrimSpace (batchID )
95- if batchID == "" || len (endpoints ) == 0 {
96- return
93+ func cloneBatchResultEndpoints (endpoints map [string ]string ) map [string ]string {
94+ if len (endpoints ) == 0 {
95+ return nil
9796 }
9897 cloned := make (map [string ]string , len (endpoints ))
9998 for customID , endpoint := range endpoints {
@@ -104,6 +103,18 @@ func (p *Provider) setBatchResultEndpoints(batchID string, endpoints map[string]
104103 }
105104 cloned [customID ] = endpoint
106105 }
106+ if len (cloned ) == 0 {
107+ return nil
108+ }
109+ return cloned
110+ }
111+
112+ func (p * Provider ) setBatchResultEndpoints (batchID string , endpoints map [string ]string ) {
113+ batchID = strings .TrimSpace (batchID )
114+ if batchID == "" || len (endpoints ) == 0 {
115+ return
116+ }
117+ cloned := cloneBatchResultEndpoints (endpoints )
107118 if len (cloned ) == 0 {
108119 return
109120 }
@@ -115,6 +126,18 @@ func (p *Provider) setBatchResultEndpoints(batchID string, endpoints map[string]
115126 p .batchEndpointsMu .Unlock ()
116127}
117128
129+ func (p * Provider ) clearBatchResultEndpoints (batchID string ) {
130+ batchID = strings .TrimSpace (batchID )
131+ if batchID == "" {
132+ return
133+ }
134+ p .batchEndpointsMu .Lock ()
135+ if p .batchResultEndpoints != nil {
136+ delete (p .batchResultEndpoints , batchID )
137+ }
138+ p .batchEndpointsMu .Unlock ()
139+ }
140+
118141func (p * Provider ) getBatchResultEndpoints (batchID string ) map [string ]string {
119142 batchID = strings .TrimSpace (batchID )
120143 if batchID == "" {
@@ -1130,6 +1153,7 @@ func (p *Provider) CreateBatch(ctx context.Context, req *core.BatchRequest) (*co
11301153 return nil , core .NewProviderError ("anthropic" , http .StatusBadGateway , "failed to map anthropic batch response" , nil )
11311154 }
11321155 mapped .ProviderBatchID = mapped .ID
1156+ mapped .RequestEndpointByCustomID = cloneBatchResultEndpoints (endpointByCustomID )
11331157 p .setBatchResultEndpoints (mapped .ProviderBatchID , endpointByCustomID )
11341158 return mapped , nil
11351159}
@@ -1214,8 +1238,7 @@ func (p *Provider) CancelBatch(ctx context.Context, id string) (*core.BatchRespo
12141238 return mapped , nil
12151239}
12161240
1217- // GetBatchResults retrieves Anthropic native message batch results.
1218- func (p * Provider ) GetBatchResults (ctx context.Context , id string ) (* core.BatchResultsResponse , error ) {
1241+ func (p * Provider ) getBatchResults (ctx context.Context , id string , endpointByCustomID map [string ]string ) (* core.BatchResultsResponse , error ) {
12191242 resp , err := p .client .DoPassthrough (ctx , llmclient.Request {
12201243 Method : http .MethodGet ,
12211244 Endpoint : "/messages/batches/" + url .PathEscape (id ) + "/results" ,
@@ -1236,7 +1259,11 @@ func (p *Provider) GetBatchResults(ctx context.Context, id string) (*core.BatchR
12361259 scanner := bufio .NewScanner (resp .Body )
12371260 // Allow larger result lines than Scanner's default 64K.
12381261 scanner .Buffer (make ([]byte , 0 , 64 * 1024 ), 4 * 1024 * 1024 )
1239- endpointByCustomID := p .getBatchResultEndpoints (id )
1262+ if len (endpointByCustomID ) == 0 {
1263+ endpointByCustomID = p .getBatchResultEndpoints (id )
1264+ } else {
1265+ endpointByCustomID = cloneBatchResultEndpoints (endpointByCustomID )
1266+ }
12401267
12411268 results := make ([]core.BatchResultItem , 0 )
12421269 index := 0
@@ -1322,6 +1349,23 @@ func (p *Provider) GetBatchResults(ctx context.Context, id string) (*core.BatchR
13221349 }, nil
13231350}
13241351
1352+ // GetBatchResults retrieves Anthropic native message batch results.
1353+ func (p * Provider ) GetBatchResults (ctx context.Context , id string ) (* core.BatchResultsResponse , error ) {
1354+ return p .getBatchResults (ctx , id , nil )
1355+ }
1356+
1357+ // GetBatchResultsWithHints retrieves Anthropic native batch results using
1358+ // persisted per-item endpoint hints instead of transient in-memory state.
1359+ func (p * Provider ) GetBatchResultsWithHints (ctx context.Context , id string , endpointByCustomID map [string ]string ) (* core.BatchResultsResponse , error ) {
1360+ return p .getBatchResults (ctx , id , endpointByCustomID )
1361+ }
1362+
1363+ // ClearBatchResultHints clears transient per-batch endpoint hints once they
1364+ // have been persisted by the gateway.
1365+ func (p * Provider ) ClearBatchResultHints (batchID string ) {
1366+ p .clearBatchResultEndpoints (batchID )
1367+ }
1368+
13251369// Embeddings returns an error because Anthropic does not natively support embeddings.
13261370// Voyage AI (Anthropic's recommended embedding provider) may be added in the future.
13271371func (p * Provider ) Embeddings (_ context.Context , _ * core.EmbeddingRequest ) (* core.EmbeddingResponse , error ) {
0 commit comments