Skip to content

CLI

Fetches all prompts 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.

Terminal window
bunx promptly generate
FlagAliasTypeDefaultDescription
--api-keystringprocess.env.PROMPTLY_API_KEYAPI key for authentication
--output-ostringAuto-detected (see below)Output file path

The CLI reads the API key in this order:

  1. --api-key flag (highest priority)
  2. PROMPTLY_API_KEY environment variable
Terminal window
# Using environment variable
PROMPTLY_API_KEY=pk_live_... npx promptly generate
# Using flag
npx promptly generate --api-key pk_live_...

The CLI automatically detects the best location for the generated file:

  1. src/types/promptly-env.d.ts - if a src/types/ directory exists
  2. types/promptly-env.d.ts - if a types/ directory exists
  3. ./promptly-env.d.ts - fallback (project root)

To override this, use the --output (-o) flag:

Terminal window
npx promptly generate --output ./custom/path/promptly-env.d.ts

The generated file is a TypeScript declaration file that augments the @promptlycms/prompts module:

promptly-env.d.ts
// Auto-generated by @promptlycms/prompts - do not edit
import '@promptlycms/prompts';
declare module '@promptlycms/prompts' {
interface PromptVariableMap {
'prompt-id': {
[V in 'latest' | '2.0.0' | '1.0.0']: {
variableName: string;
};
};
}
}

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 whose userMessage contains no ${variable} patterns get Record<string, never>:

'static-prompt': {
[V in 'latest' | '1.0.0']: Record<string, never>;
};

The CLI checks whether required provider packages are installed and warns if any are missing:

Found 3 prompt(s)
Warning: "Review Prompt" requires @ai-sdk/anthropic - install it: npm install @ai-sdk/anthropic
Generated ./promptly-env.d.ts
  1. Reads PROMPTLY_API_KEY from the environment (or --api-key flag)
  2. Calls GET /prompts?include_versions=true to fetch all prompts with their published versions
  3. Extracts ${variable} template patterns from each version’s userMessage
  4. Groups versions with identical variable sets together
  5. Sorts versions (latest first, then semver descending)
  6. Writes the declare module augmentation file
  7. Warns about any missing AI provider packages
package.json
{
"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:

Terminal window
npx promptly generate
git diff --exit-code promptly-env.d.ts