siyuan-note/siyuan · error

response returned status

Error message

response returned status %s

What it means

responseResultError accepts only empty, completed, or incomplete statuses (incomplete is handled elsewhere); any other status string — e.g. failed, cancelled, queued — is reported with this formatted error. It surfaces provider-side result statuses the caller must handle as a failed generation.

Solutions

  1. Read response.Error (or IncompleteDetails) for the provider's failure reason and fix the request accordingly
  2. Retry on transient statuses; check the provider status page on persistent failures
  3. Validate tool definitions/parameters against the API version to avoid status failed
  4. Upgrade the SDK/gateway if it emits non-standard status values
  5. Match on the formatted message or use errors from openai.APIError for structured handling
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "response returned status ") {
        status := extractStatus(err.Error()) // e.g. failed/cancelled
        log.Printf("responses api status: %s", status)
        return retryWithBackoff(ctx, req)
    }
    return err
}

Prevention

When it happens

Trigger: A Responses API result (from CreateOpenAICompletion or a terminal stream event) carries response.Status outside {"", "completed", "incomplete"} — typically "failed" or "cancelled".

Common situations: Provider rejecting the request mid-generation (invalid tool schema, unsupported parameter) yielding status failed; request cancelled client-side or by timeout; gateway returning non-standard status strings; org policy blocking the request.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/d2b6d7c3f9cbd641. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/openai_completion.go:683

				refusal.WriteString(content.Refusal)
			}
		}
	}
	return refusal.String()
}

func responseResultError(response openai.CreateResponseResponse) error {
	if response.Error != nil && response.Error.Message != "" {
		return &openai.APIError{Code: response.Error.Code, Message: response.Error.Message}
	}
	if response.Status == openai.ResponseStatusIncomplete && hasResponseFunctionCall(response.Output) {
		return errors.New("response ended with an incomplete function call")
	}
	switch response.Status {
	case "", openai.ResponseStatusCompleted, openai.ResponseStatusIncomplete:
		return nil
	default:
		return fmt.Errorf("response returned status %s", response.Status)
	}
}

func hasResponseFunctionCall(output []any) bool {
	for _, raw := range output {
		item, ok := responseOutputItem(raw)
		if ok && item.Type == "function_call" {
			return true
		}
	}
	return false
}

func responseEventError(event openai.ResponseStreamEvent, fallback string) error {
	if event.Error != nil && event.Error.Message != "" {
		return &openai.APIError{Code: event.Error.Code, Message: event.Error.Message}
	}
	if event.Response != nil && event.Response.Error != nil && event.Response.Error.Message != "" {

View on GitHub (pinned to 9f775e8a12)