You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Amp CLI requests a model that you don't have access to, you can configure mappings to route those requests to alternative models that you DO have available. This avoids consuming Amp credits for models you could handle locally.
126
+
127
+
```yaml
128
+
# Route unavailable models to alternatives
129
+
amp-model-mappings:
130
+
# Example: Route Claude Opus 4.5 requests to Claude Sonnet 4
131
+
- from: "claude-opus-4.5"
132
+
to: "claude-sonnet-4"
133
+
134
+
# Example: Route GPT-5 requests to Gemini 2.5 Pro
135
+
- from: "gpt-5"
136
+
to: "gemini-2.5-pro"
137
+
138
+
# Example: Map older model names to newer versions
139
+
- from: "claude-3-opus-20240229"
140
+
to: "claude-3-5-sonnet-20241022"
141
+
```
142
+
143
+
**How it works:**
144
+
145
+
1. Amp CLI requests a model (e.g., `claude-opus-4.5`)
146
+
2. CLIProxyAPI checks if a local provider is available for that model
147
+
3. If not available, it checks the model mappings
148
+
4. If a mapping exists, the request is rewritten to use the target model
149
+
5. The request is then handled locally (free, using your OAuth subscription)
150
+
151
+
**Benefits:**
152
+
- **Save Amp credits**: Use your local subscriptions instead of forwarding to ampcode.com
153
+
- **Hot-reload**: Mappings can be updated without restarting the proxy
154
+
- **Structured logging**: Clear logs show when mappings are applied
155
+
156
+
**Routing Decision Logs:**
157
+
158
+
The proxy logs each routing decision with structured fields:
159
+
160
+
```
161
+
[AMP] Using local provider for model: gemini-2.5-pro # Local provider (free)
162
+
[AMP] Model mapped: claude-opus-4.5 -> claude-sonnet-4 # Mapping applied (free)
log.WithFields(fields).Infof("[AMP] Model mapped: %s -> %s", requestedModel, resolvedModel)
58
+
59
+
caseRouteTypeAmpCredits:
60
+
fields["cost"] ="amp_credits"
61
+
fields["source"] ="ampcode.com"
62
+
fields["model_id"] =requestedModel// Explicit model_id for easy config reference
63
+
log.WithFields(fields).Warnf("[AMP] Forwarding to ampcode.com (uses Amp credits) - model_id: %s | To use local proxy, add to config: amp-model-mappings: [{from: \"%s\", to: \"<your-local-model>\"}]", requestedModel, requestedModel)
64
+
65
+
caseRouteTypeNoProvider:
66
+
fields["cost"] ="none"
67
+
fields["source"] ="error"
68
+
fields["model_id"] =requestedModel// Explicit model_id for easy config reference
69
+
log.WithFields(fields).Warnf("[AMP] No provider available for model_id: %s", requestedModel)
70
+
}
71
+
}
72
+
15
73
// FallbackHandler wraps a standard handler with fallback logic to ampcode.com
16
74
// when the model's provider is not available in CLIProxyAPI
17
75
typeFallbackHandlerstruct {
18
-
getProxyfunc() *httputil.ReverseProxy
76
+
getProxyfunc() *httputil.ReverseProxy
77
+
modelMapperModelMapper
19
78
}
20
79
21
80
// NewFallbackHandler creates a new fallback handler wrapper
0 commit comments