sipeed/picoclaw · error

failed to marshal request: %w

Error message

failed to marshal request: %w

What it means

Returned by OpenAITTSProvider.doSpeechRequest when json.Marshal of the {model, input, voice[, response_format]} map fails. All values are plain strings sourced from configuration, and strings always marshal, so this is unreachable in the shipped code — only a fork placing a non-marshalable type (chan, func) into reqBody could trigger it.

Source

Thrown at pkg/audio/tts/openai_tts.go:181

}

func (t *OpenAITTSProvider) doSpeechRequest(
	ctx context.Context,
	text string,
	responseFormat string,
) (io.ReadCloser, error) {
	reqBody := map[string]any{
		"model": t.model,
		"input": text,
		"voice": t.voice,
	}
	if responseFormat != "" {
		reqBody["response_format"] = responseFormat
	}

	jsonData, err := json.Marshal(reqBody)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal request: %w", err)
	}

	req, err := http.NewRequestWithContext(ctx, "POST", t.apiBase, bytes.NewReader(jsonData))
	if err != nil {
		return nil, fmt.Errorf("failed to create request: %w", err)
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+t.apiKey)

	resp, err := t.httpClient.Do(req)
	if err != nil {
		return nil, fmt.Errorf("failed to send request: %w", err)
	}

	if resp.StatusCode != http.StatusOK {
		defer resp.Body.Close()
		body, readErr := io.ReadAll(resp.Body)

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Keep reqBody values as strings
  2. In custom code, convert non-serializable values (e.g. time.Duration.String()) before adding them to the map
Defensive patterns

Strategy: validation

Try / catch

if err != nil {
    // unreachable with string-only request fields: fail fast and report as a code defect
}

Prevention

When it happens

Trigger: Modified code putting func/chan/complex values into reqBody; no configuration input can cause it.

Common situations: Custom forks of the provider only.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/ce6252b90ad0d06c. Report an issue: GitHub.