wavetermdev/waveterm · error

url must be https or data URL, got %q

Error message

url must be https or data URL, got %q

What it means

A "file" part's URL must use the https or data scheme; Validate() rejects anything else (http:, file:, ftp:, etc.) and includes the offending scheme in the message. This prevents sending insecure or unusable URLs to AI providers.

Source

Thrown at pkg/aiusechat/uctypes/uctypes.go:438

		hasURL := p.URL != ""

		if !hasData && !hasURL {
			return fmt.Errorf("file type requires either data or url")
		}

		if hasData && hasURL {
			return fmt.Errorf("file type cannot have both data and url set")
		}

		// If URL is set, validate it's https or data URL
		if hasURL {
			parsedURL, err := url.Parse(p.URL)
			if err != nil {
				return fmt.Errorf("invalid url: %w", err)
			}

			if parsedURL.Scheme != "https" && parsedURL.Scheme != "data" {
				return fmt.Errorf("url must be https or data URL, got %q", parsedURL.Scheme)
			}
		}
		return nil
	}

	return fmt.Errorf("type must be %q or %q, got %q", AIMessagePartTypeText, AIMessagePartTypeFile, p.Type)
}

// ---------------------
// AI SDK Streaming Protocol

// Type can be one of these consts...
// text-start, text-delta, text-end,
// reasoning-start, reasoning-delta, reasoning-end,
// source-url, source-document,
// file,
// data-*,
// tool-input-start, tool-input-delta, tool-input-available, tool-output-available,

View on GitHub (pinned to a4447c1563)

Solutions

  1. Serve the file over https:// and use that URL
  2. Convert small files to a data URL (data:<mime>;base64,<b64>)
  3. Set the file content as inline Data instead of a URL

Example fix

// before
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", URL: "http://cdn.example.com/a.png"}
// after
part := uctypes.AIMessagePart{Type: "file", MimeType: "image/png", Data: data}
Defensive patterns

Strategy: validation

Validate before calling

func secureFileURL(raw string) bool {
	u, err := url.Parse(raw)
	if err != nil {
		return false
	}
	return u.Scheme == "https" || u.Scheme == "data"
}

Type guard

func hasAllowedScheme(p uctypes.AIMessagePart) bool {
	u, err := url.Parse(p.URL)
	if err != nil {
		return false
	}
	return u.Scheme == "https" || u.Scheme == "data"
}

Prevention

When it happens

Trigger: AIMessagePart{Type:"file", MimeType:..., URL:"http://example.com/a.png"} or "file:///tmp/a.png" passed to Validate(); url.Parse succeeds but the scheme check fails.

Common situations: Local dev servers on http://; internal object storage with http endpoints; mistakenly putting local filesystem paths in the URL field; hosted screenshots via http-only CDNs.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/634a307ee66e3b0a. Report an issue: GitHub.