diff --git a/cmd/lk/agent.go b/cmd/lk/agent.go index e6745d0a..056d7636 100644 --- a/cmd/lk/agent.go +++ b/cmd/lk/agent.go @@ -382,12 +382,20 @@ func createAgentClientWithOpts(ctx context.Context, cmd *cli.Command, opts ...lo return ctx, err } if configExists { - projectSubdomainMatch := subdomainPattern.FindStringSubmatch(project.URL) - if len(projectSubdomainMatch) < 2 { - return ctx, fmt.Errorf("invalid project URL [%s]", project.URL) - } - if projectSubdomainMatch[1] != lkConfig.Project.Subdomain { - return ctx, fmt.Errorf("project does not match agent subdomain [%s]", lkConfig.Project.Subdomain) + // When agents_url is explicitly configured, skip subdomain validation. + // This supports self-hosted deployments where the project URL does not + // follow the .livekit.cloud pattern. + agentsURLOverride := lkConfig.Agent != nil && lkConfig.Agent.AgentsURL != "" + if !agentsURLOverride { + projectSubdomainMatch := subdomainPattern.FindStringSubmatch(project.URL) + if len(projectSubdomainMatch) < 2 { + return ctx, fmt.Errorf("invalid project URL [%s]", project.URL) + } + if projectSubdomainMatch[1] != lkConfig.Project.Subdomain { + return ctx, fmt.Errorf("project does not match agent subdomain [%s]", lkConfig.Project.Subdomain) + } + } else { + os.Setenv("LK_AGENTS_URL", lkConfig.Agent.AgentsURL) } } diff --git a/pkg/config/livekit.go b/pkg/config/livekit.go index b4da9ec9..0807c525 100644 --- a/pkg/config/livekit.go +++ b/pkg/config/livekit.go @@ -51,7 +51,8 @@ type LiveKitTOMLProjectConfig struct { } type LiveKitTOMLAgentConfig struct { - ID string `toml:"id"` + ID string `toml:"id"` + AgentsURL string `toml:"agents_url,omitempty"` } func NewLiveKitTOML(forSubdomain string) *LiveKitTOML {