JuliusBrussee/caveman · error

rewriter: build request: %w

Error message

rewriter: build request: %w

What it means

http.NewRequestWithContext refused to build the POST request for the rewriter provider — almost always because the endpoint URL string is malformed or unsupported as a request target. This is a configuration-level fault in the endpoint passed to Client.do, before any network activity.

Source

Thrown at rewriter/provider.go:179

// a caller-set temperature. The reasoning families (gpt-5*, o1/o3/o4*) do not.
func openAIAcceptsTemperature(model string) bool {
	name := strings.ToLower(strings.TrimSpace(model))
	for _, prefix := range []string{"gpt-5", "o1", "o3", "o4"} {
		if name == prefix || strings.HasPrefix(name, prefix+"-") || strings.HasPrefix(name, prefix+".") {
			return false
		}
	}
	return true
}

func (c *Client) do(ctx context.Context, endpoint string, body map[string]any, headers map[string]string) ([]byte, error) {
	encoded, err := json.Marshal(body)
	if err != nil {
		return nil, fmt.Errorf("rewriter: encode request: %w", err)
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(encoded))
	if err != nil {
		return nil, fmt.Errorf("rewriter: build request: %w", err)
	}
	req.Header.Set("content-type", "application/json")
	for key, value := range headers {
		req.Header.Set(key, value)
	}

	resp, err := c.doer(req)
	if err != nil {
		return nil, fmt.Errorf("rewriter: %s: %w", endpoint, err)
	}
	// An injected doer is caller code; a nil response or body must surface as an
	// error rather than a panic inside the proxy hot path.
	if resp == nil {
		return nil, fmt.Errorf("rewriter: %s: nil response", endpoint)
	}
	if resp.Body == nil {
		resp.Body = http.NoBody
	}

View on GitHub (pinned to 766dce6b13)

Solutions

  1. Fix the rewriter provider endpoint URL so it is a valid absolute http(s) URL
  2. Check the provider base-URL configuration for typos or missing scheme
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at rewriter/provider.go:179 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/bedc5ec11d988f6b. Report an issue: GitHub.