AgentOS Environment Configuration Service
AgentOS Environment Configuration Service
The src/lib/letmc/config.ts module provides a server-side utility for resolving AgentOS (letmc.com) API credentials and endpoint configuration from environment variables. It handles environment detection, URL validation, and offers both throwing and safe access patterns.
Overview
All AgentOS API integration in myProp flows through this configuration service. It reads environment variables at runtime, determines the correct deployment context, validates the base URL, and provides helper utilities for building API requests.
Exported API
isLetmcConfigured(): boolean
Returns true when LETMC_API_KEY is set and non-empty. Use this as a guard before calling getLetmcConfig() in code paths where the AgentOS integration is optional.
import { isLetmcConfigured } from "@/lib/letmc/config";
if (!isLetmcConfigured()) {
// Integration not set up — skip or show setup prompt
}
getLetmcConfig(): LetmcConfig
Resolves and validates the full configuration. Returns a LetmcConfig object.
Throws if:
LETMC_API_KEYis missing or empty.LETMC_API_BASE_URLis set but is not a validhttp/httpsURL.
import { getLetmcConfig } from "@/lib/letmc/config";
const config = getLetmcConfig();
// config.apiBaseUrl — resolved base URL (no trailing slash)
// config.apiKey — API key string
// config.environment — "production" | "staging" | "development"
// config.isBaseUrlOverridden — true if LETMC_API_BASE_URL was set
LetmcConfig shape:
interface LetmcConfig {
apiBaseUrl: string; // Fully-qualified base URL, no trailing slash
apiKey: string; // AgentOS API key
environment: LetmcEnvironment; // "production" | "staging" | "development"
isBaseUrlOverridden: boolean; // true when LETMC_API_BASE_URL is set
}
getLetmcConfigSafe(): LetmcConfig | null
A non-throwing variant of getLetmcConfig(). Returns null if the integration is not configured or if configuration is invalid. Configuration errors are logged as warnings.
Use this in optional feature paths where a missing AgentOS configuration should degrade gracefully rather than crash.
import { getLetmcConfigSafe } from "@/lib/letmc/config";
const config = getLetmcConfigSafe();
if (!config) {
// AgentOS not available — skip feature
return;
}
buildLetmcUrl(path: string, config?: LetmcConfig): string
Builds a fully-qualified AgentOS API URL from a relative path. Optionally accepts a pre-resolved LetmcConfig to avoid re-reading environment variables on repeated calls.
import { buildLetmcUrl } from "@/lib/letmc/config";
buildLetmcUrl("/v3/lettings/properties");
// => "https://live-api.letmc.com/v3/lettings/properties"
// With a pre-resolved config:
const config = getLetmcConfig();
buildLetmcUrl("/v3/lettings/properties", config);
Leading slashes on path are optional — they are normalised automatically.
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
LETMC_API_KEY | Yes (for integration) | — | API key for authenticating with the AgentOS API. Obtain from your AgentOS account dashboard. |
LETMC_API_BASE_URL | No | https://live-api.letmc.com | Override the API base URL. Must be a valid http/https URL. Trailing slashes are stripped automatically. |
LETMC_ENV | No | Derived | Explicit environment override. Accepts: production, staging, preview, development, dev. |
Note:
LETMC_API_KEYmust be set forgetLetmcConfig()andbuildLetmcUrl()to work.isLetmcConfigured()andgetLetmcConfigSafe()are safe to call without it.
Environment Resolution
The service detects the current deployment environment using the following priority chain:
-
LETMC_ENV— Explicit override. Takes highest priority. Useful for per-branch or per-environment configuration.production→productionstagingorpreview→stagingdevelopmentordev→development
-
VERCEL_ENV— Automatically set by the Vercel platform.production→productionpreview→stagingdevelopment→development
-
NODE_ENV— Standard Node.js environment variable.production→productiontest→staging
-
Default — Falls back to
developmentif none of the above are set.
URL Handling
- The default base URL is
https://live-api.letmc.com(the AgentOS production API endpoint). LETMC_API_BASE_URLoverrides this — useful for staging or custom deployments.- Non-
http/httpsschemes (e.g.ftp://) are rejected with an error. - Trailing slashes are automatically stripped to ensure consistent URL construction when using
buildLetmcUrl().
Middleware — Auth Bypass for Internal Routes
The Next.js middleware matcher has been updated so that internal API routes are excluded from authentication checks. The following paths bypass auth middleware automatically:
/api/health/api/inngest/api/trpc/api/webhooks/api/billing/api/feedback/api/platform-manifest/api/shell-version/api/revalidate/api/waitlist
This prevents authentication redirects from interfering with system integrations, background workers, and health-check endpoints.