CLI
promptly generate
Section titled “promptly generate”Fetches all prompts and composers from the Promptly API and generates a promptly-env.d.ts TypeScript declaration file. The CLI automatically places the file in your src/types/ or types/ directory if one exists, otherwise it falls back to the project root. Use --output to override.
bunx promptly generatenpx promptly generateyarn dlx promptly generatepnpm dlx promptly generate| Flag | Alias | Type | Default | Description |
|---|---|---|---|---|
--api-key | string | process.env.PROMPTLY_API_KEY | API key for authentication | |
--output | -o | string | Auto-detected (see below) | Output file path |
Authentication
Section titled “Authentication”The CLI reads the API key in this order:
--api-keyflag (highest priority)PROMPTLY_API_KEYenvironment variable
# Using environment variablePROMPTLY_API_KEY=pk_live_... npx promptly generate
# Using flagnpx promptly generate --api-key pk_live_...Output file
Section titled “Output file”Default location
Section titled “Default location”The CLI automatically detects the best location for the generated file:
src/types/promptly-env.d.ts- if asrc/types/directory existstypes/promptly-env.d.ts- if atypes/directory exists./promptly-env.d.ts- fallback (project root)
To override this, use the --output (-o) flag:
npx promptly generate --output ./custom/path/promptly-env.d.tsGenerated file contents
Section titled “Generated file contents”The generated file is a TypeScript declaration file that augments the @promptlycms/prompts module. When composers are present, ComposerVariableMap and ComposerPromptMap are also generated:
// Auto-generated by @promptlycms/prompts - do not editimport '@promptlycms/prompts';
declare module '@promptlycms/prompts' { interface PromptVariableMap { 'prompt-id': { [V in 'latest' | '2.0.0' | '1.0.0']: { variableName: string; }; }; } interface ComposerVariableMap { 'composer-id': { [V in 'latest' | '1.0.0']: { text: string; targetLang: string; }; }; } interface ComposerPromptMap { 'composer-id': 'translatePrompt' | 'reviewPrompt'; }}Version grouping
Section titled “Version grouping”The codegen groups versions with identical template variables together using mapped types:
// Versions 'latest', '2.0.0', and '1.0.0' all share the same variables[V in 'latest' | '2.0.0' | '1.0.0']: { pickupLocation: string; items: string;};If different versions have different variables, they are expressed as intersection types:
'my-prompt': { [V in 'latest' | '2.0.0']: { name: string; email: string; };} & { [V in '1.0.0']: { name: string; // v1 only had 'name' };};Prompts with no variables
Section titled “Prompts with no variables”Prompts whose userMessage contains no ${variable} patterns get Record<string, never>:
'static-prompt': { [V in 'latest' | '1.0.0']: Record<string, never>;};Missing provider warnings
Section titled “Missing provider warnings”The CLI checks whether required provider packages are installed and warns if any are missing. This includes models referenced by both prompts and composer prompt segments:
Found 3 prompt(s) Found 1 composer(s) Warning: "Review Prompt" requires @ai-sdk/anthropic - install it: npm install @ai-sdk/anthropic Generated ./promptly-env.d.tsHow it works
Section titled “How it works”- Reads
PROMPTLY_API_KEYfrom the environment (or--api-keyflag) - Calls
GET /prompts?include_versions=trueandGET /composers?include_versions=truein parallel - Extracts
${variable}template patterns from each prompt version’suserMessageand from composer prompt segments - Extracts prompt names from composer segments and converts them to camelCase keys
- Groups versions with identical variable sets together
- Sorts versions (latest first, then semver descending)
- Writes the
declare moduleaugmentation file withPromptVariableMap,ComposerVariableMap, andComposerPromptMap - Warns about any missing AI provider packages
Integration with build tools
Section titled “Integration with build tools”package.json script
Section titled “package.json script”{ "scripts": { "generate": "promptly generate", "prebuild": "promptly generate" }}Since the generated file should be committed to version control, you typically don’t need to run codegen in CI. But if you want to verify types are up to date:
npx promptly generategit diff --exit-code promptly-env.d.ts