()
| 281 | } |
| 282 | |
| 283 | func (c *Config) validate() error { |
| 284 | if err := c.validateServerHTTPTimeouts(); err != nil { |
| 285 | return err |
| 286 | } |
| 287 | if len(c.Backends) == 0 { |
| 288 | return fmt.Errorf("config validation: at least one backend is required") |
| 289 | } |
| 290 | |
| 291 | backendNames := make(map[string]struct{}, len(c.Backends)) |
| 292 | for _, b := range c.Backends { |
| 293 | name := strings.TrimSpace(b.Name) |
| 294 | if name == "" { |
| 295 | return fmt.Errorf("config validation: backend name cannot be empty") |
| 296 | } |
| 297 | switch b.Type { |
| 298 | case "mock": |
| 299 | case "vllm", "openai", "openai_compatible", "azure_openai": |
| 300 | if strings.TrimSpace(b.Endpoint) == "" { |
| 301 | return fmt.Errorf("config validation: backend %q type %q requires endpoint", b.Name, b.Type) |
| 302 | } |
| 303 | if b.Type == "azure_openai" && strings.TrimSpace(b.DefaultModel) == "" { |
| 304 | return fmt.Errorf("config validation: backend %q type azure_openai requires default_model (Azure deployment name)", b.Name) |
| 305 | } |
| 306 | case "anthropic": |
| 307 | if strings.TrimSpace(b.APIKey) == "" { |
| 308 | return fmt.Errorf("config validation: backend %q type anthropic requires api_key", b.Name) |
| 309 | } |
| 310 | if strings.TrimSpace(b.DefaultModel) == "" { |
| 311 | return fmt.Errorf("config validation: backend %q type anthropic requires default_model", b.Name) |
| 312 | } |
| 313 | case "bedrock": |
| 314 | if strings.TrimSpace(b.AWSRegion) == "" { |
| 315 | return fmt.Errorf("config validation: backend %q type bedrock requires aws_region", b.Name) |
| 316 | } |
| 317 | if strings.TrimSpace(b.DefaultModel) == "" { |
| 318 | return fmt.Errorf("config validation: backend %q type bedrock requires default_model (Bedrock model ID)", b.Name) |
| 319 | } |
| 320 | case "gemini": |
| 321 | // endpoint optional; empty uses https://generativelanguage.googleapis.com in adapter |
| 322 | if strings.TrimSpace(b.APIKey) == "" { |
| 323 | return fmt.Errorf("config validation: backend %q type gemini requires api_key", b.Name) |
| 324 | } |
| 325 | if strings.TrimSpace(b.DefaultModel) == "" { |
| 326 | return fmt.Errorf("config validation: backend %q type gemini requires default_model", b.Name) |
| 327 | } |
| 328 | case "gemini_vertex": |
| 329 | if strings.TrimSpace(b.VertexProject) == "" || strings.TrimSpace(b.VertexLocation) == "" { |
| 330 | return fmt.Errorf("config validation: backend %q type gemini_vertex requires vertex_project and vertex_location", b.Name) |
| 331 | } |
| 332 | if strings.TrimSpace(b.APIKey) == "" { |
| 333 | return fmt.Errorf("config validation: backend %q type gemini_vertex requires api_key (OAuth access token or compatible bearer)", b.Name) |
| 334 | } |
| 335 | if strings.TrimSpace(b.DefaultModel) == "" { |
| 336 | return fmt.Errorf("config validation: backend %q type gemini_vertex requires default_model", b.Name) |
| 337 | } |
| 338 | default: |
| 339 | return fmt.Errorf("config validation: unsupported backend type %q for backend %q", b.Type, b.Name) |
| 340 | } |
no test coverage detected