Skip to content

Commit 63c3c8b

Browse files
committed
chore: sync with upstream v0.34.3, preserve bedrock inference profile fixes
1 parent e1aead9 commit 63c3c8b

2 files changed

Lines changed: 113 additions & 23 deletions

File tree

internal/providers/configs/bedrock.json

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"context_window": 1000000,
1818
"default_max_tokens": 64000,
1919
"can_reason": true,
20-
"supports_attachments": true
20+
"supports_attachments": true,
21+
"regions": ["us", "eu", "jp", "au", "global"]
2122
},
2223
{
2324
"id": "anthropic.claude-sonnet-4-5-20250929-v1:0",
@@ -29,7 +30,8 @@
2930
"context_window": 200000,
3031
"default_max_tokens": 64000,
3132
"can_reason": true,
32-
"supports_attachments": true
33+
"supports_attachments": true,
34+
"regions": ["us", "eu", "jp", "au", "global"]
3335
},
3436
{
3537
"id": "anthropic.claude-haiku-4-5-20251001-v1:0",
@@ -41,7 +43,8 @@
4143
"context_window": 200000,
4244
"default_max_tokens": 64000,
4345
"can_reason": false,
44-
"supports_attachments": true
46+
"supports_attachments": true,
47+
"regions": ["us", "eu", "jp", "au", "global"]
4548
},
4649
{
4750
"id": "anthropic.claude-opus-4-6-v1",
@@ -53,7 +56,8 @@
5356
"context_window": 1000000,
5457
"default_max_tokens": 126000,
5558
"can_reason": true,
56-
"supports_attachments": true
59+
"supports_attachments": true,
60+
"regions": ["us", "eu", "au", "global"]
5761
},
5862
{
5963
"id": "anthropic.claude-opus-4-5-20251101-v1:0",
@@ -65,19 +69,21 @@
6569
"context_window": 200000,
6670
"default_max_tokens": 64000,
6771
"can_reason": true,
68-
"supports_attachments": true
72+
"supports_attachments": true,
73+
"regions": ["us", "eu", "global"]
6974
},
7075
{
71-
"id": "anthropic.claude-opus-4-1-20250805-v1:0",
72-
"name": "AWS Claude Opus 4.1",
73-
"cost_per_1m_in": 15,
74-
"cost_per_1m_out": 75,
75-
"cost_per_1m_in_cached": 18.75,
76-
"cost_per_1m_out_cached": 1.5,
76+
"id": "anthropic.claude-sonnet-4-20250514-v1:0",
77+
"name": "AWS Claude Sonnet 4",
78+
"cost_per_1m_in": 3,
79+
"cost_per_1m_out": 15,
80+
"cost_per_1m_in_cached": 3.75,
81+
"cost_per_1m_out_cached": 0.3,
7782
"context_window": 200000,
78-
"default_max_tokens": 32000,
83+
"default_max_tokens": 64000,
7984
"can_reason": true,
80-
"supports_attachments": true
85+
"supports_attachments": true,
86+
"regions": ["us", "eu", "apac", "global"]
8187
},
8288
{
8389
"id": "anthropic.claude-opus-4-20250514-v1:0",
@@ -89,19 +95,21 @@
8995
"context_window": 200000,
9096
"default_max_tokens": 32000,
9197
"can_reason": true,
92-
"supports_attachments": true
98+
"supports_attachments": true,
99+
"regions": ["us"]
93100
},
94101
{
95-
"id": "anthropic.claude-sonnet-4-20250514-v1:0",
96-
"name": "AWS Claude Sonnet 4",
97-
"cost_per_1m_in": 3,
98-
"cost_per_1m_out": 15,
99-
"cost_per_1m_in_cached": 3.75,
100-
"cost_per_1m_out_cached": 0.3,
102+
"id": "anthropic.claude-opus-4-1-20250805-v1:0",
103+
"name": "AWS Claude Opus 4.1",
104+
"cost_per_1m_in": 15,
105+
"cost_per_1m_out": 75,
106+
"cost_per_1m_in_cached": 18.75,
107+
"cost_per_1m_out_cached": 1.5,
101108
"context_window": 200000,
102-
"default_max_tokens": 64000,
109+
"default_max_tokens": 32000,
103110
"can_reason": true,
104-
"supports_attachments": true
111+
"supports_attachments": true,
112+
"regions": ["us"]
105113
}
106114
]
107115
}

internal/providers/providers.go

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ package providers
44
import (
55
_ "embed"
66
"encoding/json"
7+
"fmt"
78
"log"
9+
"os"
10+
"slices"
11+
"strings"
812

913
"charm.land/catwalk/pkg/catwalk"
1014
)
@@ -170,7 +174,85 @@ func azureProvider() catwalk.Provider {
170174
}
171175

172176
func bedrockProvider() catwalk.Provider {
173-
return loadProviderFromConfig(bedrockConfig)
177+
p := loadProviderFromConfig(bedrockConfig)
178+
179+
region := os.Getenv("AWS_REGION")
180+
if region == "" {
181+
region = os.Getenv("AWS_DEFAULT_REGION")
182+
}
183+
184+
regionsByModelID, err := loadBedrockRegionsByModelID()
185+
if err != nil {
186+
log.Printf("Error loading bedrock regions: %v", err)
187+
return catwalk.Provider{}
188+
}
189+
190+
prefix := bedrockRegionPrefix(region)
191+
origLarge := p.DefaultLargeModelID
192+
origSmall := p.DefaultSmallModelID
193+
194+
resolved := make([]catwalk.Model, 0, len(p.Models))
195+
for _, m := range p.Models {
196+
id := m.ID
197+
regions := regionsByModelID[id]
198+
199+
switch {
200+
case slices.Contains(regions, prefix):
201+
m.ID = prefix + "." + m.ID
202+
case slices.Contains(regions, "global"):
203+
m.ID = "global." + m.ID
204+
default:
205+
continue
206+
}
207+
208+
if id == origLarge {
209+
p.DefaultLargeModelID = m.ID
210+
}
211+
if id == origSmall {
212+
p.DefaultSmallModelID = m.ID
213+
}
214+
resolved = append(resolved, m)
215+
}
216+
p.Models = resolved
217+
218+
return p
219+
}
220+
221+
// bedrockRegionPrefix maps an AWS region to the inference profile prefix used
222+
// by Bedrock cross-region inference. Returns an empty string when the region
223+
// is unknown or unset, in which case the global profile is used as fallback.
224+
func bedrockRegionPrefix(region string) string {
225+
switch {
226+
case strings.HasPrefix(region, "us-") || region == "ca-central-1":
227+
return "us"
228+
case strings.HasPrefix(region, "eu-"):
229+
return "eu"
230+
case region == "ap-northeast-1":
231+
return "jp"
232+
case region == "ap-southeast-2":
233+
return "au"
234+
default:
235+
return ""
236+
}
237+
}
238+
239+
func loadBedrockRegionsByModelID() (map[string][]string, error) {
240+
var config struct {
241+
Models []struct {
242+
ID string `json:"id"`
243+
Regions []string `json:"regions"`
244+
} `json:"models"`
245+
}
246+
247+
if err := json.Unmarshal(bedrockConfig, &config); err != nil {
248+
return nil, fmt.Errorf("unmarshal bedrock config: %w", err)
249+
}
250+
251+
regionsByModelID := make(map[string][]string, len(config.Models))
252+
for _, model := range config.Models {
253+
regionsByModelID[model.ID] = model.Regions
254+
}
255+
return regionsByModelID, nil
174256
}
175257

176258
func vertexAIProvider() catwalk.Provider {

0 commit comments

Comments
 (0)