StripThinkingConfig removes thinking configuration fields from request body. This function is used when a model doesn't support thinking but the request contains thinking configuration. The configuration is silently removed to prevent upstream API errors. Parameters: - body: Original request body
(body []byte, provider string)
| 23 | // - provider is unknown |
| 24 | // - no thinking configuration found |
| 25 | func StripThinkingConfig(body []byte, provider string) []byte { |
| 26 | if len(body) == 0 || !gjson.ValidBytes(body) { |
| 27 | return body |
| 28 | } |
| 29 | |
| 30 | var paths []string |
| 31 | switch provider { |
| 32 | case "claude": |
| 33 | paths = []string{"thinking", "output_config.effort"} |
| 34 | case "gemini": |
| 35 | paths = []string{"generationConfig.thinkingConfig"} |
| 36 | case "antigravity": |
| 37 | paths = []string{"request.generationConfig.thinkingConfig"} |
| 38 | case "openai": |
| 39 | paths = []string{"reasoning_effort"} |
| 40 | case "kimi": |
| 41 | paths = []string{ |
| 42 | "reasoning_effort", |
| 43 | "thinking", |
| 44 | } |
| 45 | case "codex", "xai": |
| 46 | paths = []string{"reasoning.effort"} |
| 47 | default: |
| 48 | return body |
| 49 | } |
| 50 | |
| 51 | result := body |
| 52 | for _, path := range paths { |
| 53 | result, _ = sjson.DeleteBytes(result, path) |
| 54 | } |
| 55 | |
| 56 | // Avoid leaving an empty output_config object for Claude when effort was the only field. |
| 57 | if provider == "claude" { |
| 58 | if oc := gjson.GetBytes(result, "output_config"); oc.Exists() && oc.IsObject() && len(oc.Map()) == 0 { |
| 59 | result, _ = sjson.DeleteBytes(result, "output_config") |
| 60 | } |
| 61 | } |
| 62 | return result |
| 63 | } |