AlexxIT/go2rtc · error

failed to load webrtc config

Error message

failed to load webrtc config: %w

What it means

go2rtc's Tuya smart API client wraps any failure from loadWebrtcConfig() during initialization with this message. loadWebrtcConfig fetches the WebRTC signaling configuration (STUN/TURN/relay endpoints) from the Tuya cloud for the configured skill/region. Without it the client cannot start its MQTT-based signaling session, so Start() aborts.

Solutions

  1. Verify Tuya accessId/accessKey and countryCode/region match the account in the Tuya IoT platform
  2. Log the wrapped inner error (%w) to see whether it is HTTP 4xx/5xx, DNS, or a parse failure
  3. Confirm the device/skill actually supports WebRTC streaming in the Tuya cloud console
  4. Check network connectivity and proxy/firewall rules to Tuya API endpoints
  5. Retry after confirming the token is fresh; token expiry mid-flow can cascade into config fetch failure

Example fix

// before
c := tuya.NewSmartAPI(accessID, accessKey, "eu") // wrong region for account
err := c.Start()
// after
c := tuya.NewSmartAPI(accessID, accessKey, "us") // region matching Tuya account
if err := c.Start(); err != nil {
    log.Errorf("tuya start: %v", err) // inspect wrapped cause
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: validate config before Start()
if accessID == "" || accessKey == "" { return errors.New("tuya credentials missing") }
if !validRegion(countryCode) { return fmt.Errorf("unsupported region %q", countryCode) }
if err := pingTuyaAPI(region); err != nil { return fmt.Errorf("tuya API unreachable: %w", err) }

Type guard

func hasWebrtcSkill(s *tuya.Skill) bool { return s != nil && s.WebRTC }

Try / catch

if err := c.Start(); err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) { /* retry with backoff */ }
    else if strings.Contains(err.Error(), "failed to load webrtc config") { /* check credentials/region */ }
    return err
}

Prevention

When it happens

Trigger: Calling TuyaSmartAPI Start() (or equivalent init path) when the HTTP request to Tuya's webrtc-config endpoint fails: bad accessId/accessKey, wrong region/country code, expired token despite initToken succeeding, network outage, or Tuya returning an error body.

Common situations: Incorrect region/endpoint configured for the Tuya IoT account; cloud API credentials revoked or quota exhausted; corporate firewall blocking Tuya API hosts; Tuya skill data missing WebRTC section for the device.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/dbb61ae27d0f62ad. Report an issue: GitHub.

Appendix: source

Thrown at pkg/tuya/smart_api.go:305

			baseUrl:    baseUrl,
		},
		email:       email,
		password:    password,
		countryCode: region.Continent,
	}

	return client, nil
}

// WebRTC Flow
func (c *TuyaSmartApiClient) Init() error {
	if err := c.initToken(); err != nil {
		return fmt.Errorf("failed to initialize token: %w", err)
	}

	webrtcConfig, err := c.loadWebrtcConfig()
	if err != nil {
		return fmt.Errorf("failed to load webrtc config: %w", err)
	}

	hubConfig, err := c.loadHubConfig()
	if err != nil {
		return fmt.Errorf("failed to load hub config: %w", err)
	}

	if err := c.mqtt.Start(hubConfig, webrtcConfig, c.skill.WebRTC); err != nil {
		return fmt.Errorf("failed to start MQTT: %w", err)
	}

	if c.skill.LowPower > 0 {
		_ = c.mqtt.WakeUp(c.localKey)
	}

	return nil
}

View on GitHub (pinned to c245815e75)