pnpm dev), Vitest, or Node scripts directly against your real hosted ohmyho.st Dev (or Prod) resources — without installing or maintaining local PostgreSQL, R2, or Resend emulators.
Your server code calls resolveOhMyHostEnv(workerEnv) once:
- In Cloudflare Workers (hosted Dev / Prod): returns
workerEnvuntouched with zero network overhead. - Locally (
pnpm dev, Vitest, scripts): returns the exact sameenvbindings backed by the Owner-authenticated Cloud Runtime Bridge onhttps://app.ohmyho.st.
Prefer letting your coding agent set this up? The
ohmyhost-build-portable-app Skill includes the matching local development reference so agents wire .env.local, resolveOhMyHostEnv, and ohmyhost dev automatically.1. Create an Owner API token and configure .env.local
Local cloud development requires an Owner API token with projects:write (or the narrower Owner-only runtime:use permission) and your project ULID.
- Find your organization ULID and project ULID:
- Create an Owner API token in the portal at app.ohmyho.st/tokens (default full permission set) or, for least privilege, with the CLI (in a shell where
OHMYHOST_TOKENis unset). Pass--permissions runtime:use(CLI>= 0.1.91) so the local token can only reach the Cloud Runtime Bridge and cannot modify projects or billing:
ohmyhost token create --out writes OHMYHOST_TOKEN=... (the CLI automation variable). Local runtime resolution reads OHMYHOST_API_TOKEN so your interactive CLI login and your application’s local runtime bridge stay cleanly separated.
- Add the token and project ULID to
.env.localin your application root (and verify.env.localis in.gitignore):
Environment variable reference
Free vs Paid environment targeting
2. Install the runtime package alias
Install@amerged/ohmyhost-runtime under the @ohmyhost/customer-runtime alias (matching ohmyhost init --dry-run --json) and commit the updated lockfile:
@ohmyhost/customer-runtime (required for hosted builds) and @amerged/ohmyhost-runtime export resolveOhMyHostEnv and DATABASE_CLIENT_LIMITS for both ESM (import) and Node 22.12+ CommonJS/tsx (require()).
3. Resolve bindings in server code
CallresolveOhMyHostEnv(workerEnv) in server-only code (calling it in a browser throws runtime_env_invalid).
Next.js (App Router / OpenNext)
In Next.js Route Handlers and Server Components, wrapgetCloudflareContext({ async: true }) in a try/catch so next dev falls back cleanly to .env.local:
Vite API companion, TanStack Start, Astro SSR, plain Workers, Vitest, and Node scripts
Pass your runtimeenv when available, or omit it (undefined) in local scripts and tests:
4. Use hosted capabilities locally
Every binding returned byresolveOhMyHostEnv matches the deployed Cloudflare Worker shape:
PostgreSQL (OHMYHOST_DATABASE)
Always pass both text and values (values: [] when there are no parameters; omitting values throws database_query_invalid):
withConnection and withRls, the runtime exchanges your bearer token over HTTPS for a single-use 30-second HMAC WebSocket ticket so your API token never appears in a WebSocket URL. See Postgres queries, writes and compute and Row-level security for query limits and Kysely usage.
Database client limits (DATABASE_CLIENT_LIMITS) and PostgreSQL column types
Import DATABASE_CLIENT_LIMITS from @ohmyhost/customer-runtime/database to mirror the exact limits enforced both locally and hosted:
PostgreSQL column type mapping:
int8/bigint(includingCOUNT(*)): returned as a decimalstringto preserve 64-bit precision (parse withBigInt(...)orNumber(...)where safe).numeric/decimal: returned asstring.date: returned asYYYY-MM-DDstring.timestamptz: returned as a JavaScriptDate.bytea: returned asUint8Array.json/jsonb: returned as parsed JavaScript values.
Private files (OHMYHOST_STORAGE_*)
Private storage requires storage declared in ohmyhost.yaml and deploying the target environment at least once (otherwise the bridge returns 403 gateway_not_enabled).
Transactional mail (OHMYHOST_MAIL_*)
mail.send() returns messageId, an outbound provider identifier (typically a UUID; absent when state is uncertain); ohmyhost mail messages list|get|retry inspects inbound received mail using its inbound ULID, not outbound send identifiers. See Email.
AI gateway (OHMYHOST_AI_*) and Browser PDF (OHMYHOST_BROWSER_*)
- AI gateway: works immediately from local development on Paid workspaces with credits — even before enabling
aiinohmyhost.yamland deploying. Local AI defaults toanyunless you setOHMYHOST_AI_JURISDICTION=euor the active deployment is locked toeu. Every non-WebSocket AI response carriesx-request-id, andGET /v1/modelsincludesx-ohmyhost-ai-jurisdiction(euorany). - Browser PDF: requires Paid access, credits, and an active deployment whose
ohmyhost.yamlenablesbrowser.enabled: true(otherwise the bridge returns403 gateway_not_enabled).
Container jobs (OHMYHOST_JOBS_*) and Native Auth (OHMYHOST_AUTH)
- Container jobs: call
${env.OHMYHOST_JOBS_BASE_URL}/v1/...withAuthorization: Bearer ${env.OHMYHOST_JOBS_TOKEN}. See Container jobs. - Native Auth: pass
env.OHMYHOST_AUTHtocreateNativeAuthServer(env.OHMYHOST_AUTH)and useauth.getSession(request)orauth.requireUser(request). See Application authentication.
5. Secrets separation (.env.local vs Secret Manager)
- Platform bindings (
OHMYHOST_*): provided locally byresolveOhMyHostEnvand injected automatically by ohmyho.st when deployed. Never addOHMYHOST_*names to the platform Secret Manager. - Third-party and application secrets (such as
STRIPE_SECRET_KEY,APP_AUTH_SECRET,APP_URL): stay in.env.localduring local development and remain write-only in the platform Secret Manager when deployed. ohmyho.st never pulls secret values back down to your laptop; upload them separately for Dev and Prod usingohmyhost secret setorohmyhost secret form create.
6. Local edge parity, crons, webhooks, and live logs
The CLI (@amerged/ohmyhost-cli >= 0.1.87; --permissions on token create requires >= 0.1.91) provides local parity commands that read your ohmyhost.yaml and .env.local:
Run your Worker locally with egress parity (ohmyhost dev --edge)
127.0.0.1 with the Cloud Runtime Bridge bindings and enforces runtime.egress.allow from ohmyhost.yaml — blocking unlisted or retired hosts with HTTP 403 (Outbound request blocked) and refusing redirects with HTTP 502, matching hosted Workers.
Trigger scheduled cron handlers locally (ohmyhost dev cron trigger)
functions.crons in ohmyhost.yaml before dispatching scheduled(controller, env, ctx).
Replay signed webhooks locally (ohmyhost dev webhook replay)
webhook-id, webhook-timestamp, webhook-signature) and delivers it strictly to loopback (127.0.0.1, localhost, [::1]) without printing secrets.
Follow live hosted runtime logs (ohmyhost deployment logs --follow)
5xx and uncaught exception diagnostics (route, status_code, request_id, duration_ms, and safe exception_class — never exception messages, query strings, or secrets) until interrupted.
7. Troubleshooting
CLI · Postgres · Runtime secrets · Troubleshooting.