GetModel returns a specific model by ID. The ID must carry both a provider and a model component; pass the result of [NewID], [ParseID], or a provider's [ID] method.
(ctx context.Context, id ID)
| 217 | // provider and a model component; pass the result of [NewID], [ParseID], |
| 218 | // or a provider's [ID] method. |
| 219 | func (s *Store) GetModel(ctx context.Context, id ID) (*Model, error) { |
| 220 | if !id.IsValid() { |
| 221 | return nil, fmt.Errorf("invalid model ID: %q", id.String()) |
| 222 | } |
| 223 | |
| 224 | provider, err := s.getProvider(ctx, id.Provider) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | |
| 229 | model, exists := provider.Models[id.Model] |
| 230 | |
| 231 | // For amazon-bedrock, try stripping region/inference profile prefixes. |
| 232 | // Bedrock uses prefixes for cross-region inference profiles, |
| 233 | // but models.dev stores models without these prefixes. |
| 234 | if !exists && id.Provider == "amazon-bedrock" { |
| 235 | if prefix, after, ok := strings.Cut(id.Model, "."); ok && bedrockRegionPrefixes[prefix] { |
| 236 | model, exists = provider.Models[after] |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | if !exists { |
| 241 | return nil, fmt.Errorf("model %q not found in provider %q", id.Model, id.Provider) |
| 242 | } |
| 243 | |
| 244 | return &model, nil |
| 245 | } |
| 246 | |
| 247 | // loadDatabase loads the database from the local cache file or |
| 248 | // falls back to fetching from the models.dev API. |