Run one validation probe, retrying with its fallback body only when the upstream specifically rejected `max_completion_tokens`. That retry exists for the GPT-5+ (`max_completion_tokens`) versus legacy (`max_tokens`) chat split. Firing it for any request-shape rejection would issue a second, pointless probe when the real signal is "wrong protocol for this model", and a transient `429`/`5xx` on tha
(
client: &reqwest::Client,
route: &ResolvedRoute,
probe: &ValidationProbe,
headers: &[(String, String)],
)
| 505 | /// terminal failure that stops the caller from reaching a protocol that would |
| 506 | /// have validated. |
| 507 | async fn try_validation_probe( |
| 508 | client: &reqwest::Client, |
| 509 | route: &ResolvedRoute, |
| 510 | probe: &ValidationProbe, |
| 511 | headers: &[(String, String)], |
| 512 | ) -> Result<ValidatedEndpoint, ValidationFailure> { |
| 513 | let result = try_validation_request( |
| 514 | client, |
| 515 | route, |
| 516 | probe.path, |
| 517 | probe.protocol, |
| 518 | headers, |
| 519 | probe.body.clone(), |
| 520 | ) |
| 521 | .await; |
| 522 | |
| 523 | if let (Err(err), Some(fallback_body)) = (&result, &probe.fallback_body) |
| 524 | && err.kind == ValidationFailureKind::RequestShape |
| 525 | && err.details.contains("max_completion_tokens") |
| 526 | { |
| 527 | return try_validation_request( |
| 528 | client, |
| 529 | route, |
| 530 | probe.path, |
| 531 | probe.protocol, |
| 532 | headers, |
| 533 | fallback_body.clone(), |
| 534 | ) |
| 535 | .await; |
| 536 | } |
| 537 | |
| 538 | result |
| 539 | } |
| 540 | |
| 541 | /// Send a single validation request and classify the response. |
| 542 | async fn try_validation_request( |
no test coverage detected