different-ai/openwork · error
DEN_API_PUBLIC_URL must be an absolute http or https URL.
Error message
DEN_API_PUBLIC_URL must be an absolute http or https URL.
What it means
This error is thrown by normalizeConfiguredPublicApiBaseUrl when the DEN_API_PUBLIC_URL environment variable is set but cannot be parsed as an absolute URL by the URL constructor — e.g. it lacks a scheme or is malformed. The variable defines the externally visible base URL for building public API links, so it must be a valid absolute http/https URL.
Source
Thrown at ee/apps/den-api/src/request-url.ts:96
function isLocalPublicApiHost(hostname: string): boolean {
const normalized = hostname.toLowerCase().replace(/^\[|\]$/g, "")
return normalized === "localhost"
|| normalized.endsWith(".localhost")
|| normalized === "127.0.0.1"
|| normalized === "::1"
}
export function normalizeConfiguredPublicApiBaseUrl(
value: string | undefined,
options: { allowInsecureHttp: boolean },
): string | undefined {
const configured = value?.trim()
if (!configured) return undefined
let url: URL
try {
url = new URL(configured)
} catch {
throw new Error("DEN_API_PUBLIC_URL must be an absolute http or https URL.")
}
if (url.protocol !== "http:" && url.protocol !== "https:") {
throw new Error("DEN_API_PUBLIC_URL must be an absolute http or https URL.")
}
if (url.username || url.password || url.search || url.hash) {
throw new Error("DEN_API_PUBLIC_URL cannot contain credentials, a query string, or a fragment.")
}
if (url.protocol !== "https:" && !options.allowInsecureHttp && !isLocalPublicApiHost(url.hostname)) {
throw new Error("DEN_API_PUBLIC_URL must use HTTPS outside development and localhost.")
}
const pathname = url.pathname.replace(/\/+$/, "")
return `${url.origin}${pathname === "/" ? "" : pathname}`
}
View on GitHub (pinned to 2b7df46e8a)
Solutions
- Set DEN_API_PUBLIC_URL to a fully qualified URL including scheme, e.g. https://api.example.com.
- Check the deployment environment/secret store for stray whitespace or quotes around the value and trim them.
- If the variable is optional in your setup, unset it entirely instead of leaving an invalid partial value.
- Add a startup env validation step (e.g. Zod .url()) so misconfiguration fails fast with a clear message.
Example fix
// before DEN_API_PUBLIC_URL=api.openworklabs.com // after DEN_API_PUBLIC_URL=https://api.openworklabs.com
Defensive patterns
Strategy: validation
Validate before calling
const v = process.env.DEN_API_PUBLIC_URL?.trim()
if (v) {
let u: URL
try { u = new URL(v) } catch { throw new Error("DEN_API_PUBLIC_URL must be an absolute http or https URL") }
if (u.protocol !== "http:" && u.protocol !== "https:") throw new Error("DEN_API_PUBLIC_URL must be an absolute http or https URL")
} Type guard
function isAbsoluteHttpUrl(value: string | undefined): value is string {
if (!value) return false
try { const u = new URL(value); return u.protocol === "http:" || u.protocol === "https:" } catch { return false }
} Try / catch
try {
const baseUrl = apiPublicUrl(env)
} catch (e) {
if (e.message.includes("DEN_API_PUBLIC_URL")) {
throw new Error(`Startup config invalid: set DEN_API_PUBLIC_URL to e.g. https://api.example.com (${e.message})`)
}
throw e
} Prevention
- Always include the scheme (https://) in env-provided URLs
- Validate env vars at startup with Zod (.url()) so failures are immediate and clear
- Trim and strip quotes from env values in deploy templates
- Document the expected format next to the variable in deployment configs
When it happens
Trigger: apiPublicUrl reads DEN_API_PUBLIC_URL with a value like "api.example.com", "localhost:3000", "//host", or containing spaces; new URL(configured) throws and this Error propagates at startup or first URL build.
Common situations: Deploy config omits the https:// scheme; a trailing quote/space leaked into the env var; a relative path was supplied; the value was set in one environment but pasted incorrectly in another (Docker env, Terraform, Railway/Render dashboard).
Related errors
- DEN_DIAGNOSTICS_ORIGIN must be an absolute http or https ori
- DEN_DIAGNOSTICS_ORIGIN cannot contain credentials, a path, a
- ${envName} must be an absolute https origin.
- DEN_API_PUBLIC_URL cannot contain credentials, a query strin
- DEN_API_PUBLIC_URL must use HTTPS outside development and lo
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/4610f70d6a1e89c3.
Report an issue: GitHub.