Gateway: auto-resolve request shape per provider and model

An upstream that rejects a key the gateway adds (e.g. thinking) now gets
retried with other shapes on a parsable 400/422; the working method is
stored per (provider, target model) and applied first-try from then on.
Fallback attempts are re-shaped per attempt. Admin list/reset, Devii
tools, audit event and ledger resolved_method included.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:34:26 +01:00
co-authored by Claude Sonnet 5.5
parent 3f6e83c753
commit 151476125f
22 changed files with 1597 additions and 129 deletions
+9 -1
View File
@@ -56,7 +56,15 @@
{% if m.kind == 'image' and m.price_input_per_m %}<span class="gw-badge" title="Flat price per generated image">${{ m.price_input_per_m }}/img</span>{% endif %}
{% if m.fallback_model %}<span class="gw-badge" title="Falls back to {{ m.fallback_model }} on failure">fallback: {{ m.fallback_model }}</span>{% endif %}
{% if m.tools_mode == 'emulated' %}<span class="gw-badge" title="This model does not support tool calling; tools are emulated through the prompt">tools: emulated</span>{% endif %}
{% if not m.context_tier_threshold_tokens and m.off_peak_start_minute is none and not (m.kind == 'image' and m.price_input_per_m) and not m.fallback_model and m.tools_mode != 'emulated' %}<span class="gw-muted">-</span>{% endif %}
{% if m.learned_shape %}
<span class="gw-badge" title="Request shape learned automatically after the upstream rejected the default">shape: {{ m.learned_shape }}</span>
<form method="post" action="/admin/gateway/learned/reset-page" class="gw-inline-form">
<input type="hidden" name="provider" value="{{ m.learned_provider }}">
<input type="hidden" name="target_model" value="{{ m.target_model }}">
<button type="submit" class="admin-btn admin-btn-sm" data-confirm="Forget the learned request shape for &quot;{{ m.target_model }}&quot;?">Reset learned</button>
</form>
{% endif %}
{% if not m.context_tier_threshold_tokens and m.off_peak_start_minute is none and not (m.kind == 'image' and m.price_input_per_m) and not m.fallback_model and m.tools_mode != 'emulated' and not m.learned_shape %}<span class="gw-muted">-</span>{% endif %}
</td>
<td>
{% if m.health_status == 'bad' %}