PromptMia Info

API Reference

PromptMia provides a REST API for managing prompt templates, compiling variable-filled prompts, and automating workflows — from scripts, CI pipelines, or AI agents.

Base URL

https://promptmia.com

All API responses are application/json unless otherwise noted. Timestamps are ISO 8601 UTC strings.

Authentication

Protected endpoints accept two auth methods. Most programmatic use cases should use API keys.

Recommended

API Key (Bearer token)

Generate a key in Settings. The raw key is shown once on creation — store it securely. Keys start with pt_.

Authorization: Bearer pt_your_api_key_here

Session Cookie (browser)

The browser session set by POST /api/auth/login is accepted by all protected endpoints. Not recommended for programmatic use — prefer API keys.

Note

API key management endpoints (GET/POST/DELETE /api/keys) require a browser session — they cannot be called via API key auth.

Variable Syntax

Template content uses {{variable}} placeholders. When compiled, each placeholder is replaced with its value (or [name] if not provided).

SyntaxTypeNotes
{{name}}textDefault type, max 128 chars
{{name|text}}textExplicit single-line text
{{name|textarea:512}}textareaMulti-line text, max 512 chars
{{name|number}}numberNumeric input
{{name|email}}emailEmail address
{{name|phone}}phonePhone number
{{name|list}}listComma-separated values
{{name|type:maxLen|hint}}anyAll three segments: type, max length, description

Quick Start

The most common use case: create a template, then compile it with variable values to get a ready-to-use prompt string.

JavaScript
// Install: npm install node-fetch (or use native fetch in Node 18+)

const BASE = 'https://promptmia.com'
const API_KEY = 'pt_your_api_key_here'

const headers = {
  'Authorization': `Bearer ${API_KEY}`,
  'Content-Type': 'application/json',
}

// 1. Create a template
const { template } = await fetch(`${BASE}/api/templates`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    title: 'Blog Post Intro',
    content: 'Write an intro for a blog post about {{topic|text}} for a {{audience|text}} audience.',
    tags: ['writing'],
  }),
}).then(r => r.json())

// 2. Compile with variable values
const { compiled, missing_variables } = await fetch(`${BASE}/api/templates/${template.id}/compile`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    variables: { topic: 'AI agents', audience: 'developers' },
  }),
}).then(r => r.json())

console.log(compiled)
// → "Write an intro for a blog post about AI agents for a developers audience."

Templates

GET/api/templates

List all templates owned by the authenticated user, ordered by most recently updated.

Auth: API key or session

Response

{
  "templates": [
    {
      "id": "uuid",
      "title": "Customer Support Reply",
      "description": "...",
      "tags": ["support"],
      "is_public": false,
      "created_at": "2026-01-01T00:00:00Z",
      "updated_at": "2026-01-02T00:00:00Z"
    }
  ]
}

Example

curl
curl https://promptmia.com/api/templates \
  -H "Authorization: Bearer pt_your_api_key_here"
POST/api/templates

Create a new template.

Auth: API key or session

Request body

NameTypeRequiredDescription
titlestringyesTemplate name (1–255 chars)
contentstringyesMarkdown content with {{variable}} placeholders
descriptionstringnoOptional short description
tagsstring[]noTag list for filtering
is_publicbooleannoWhether to list on explore page (default: false)

Response

{
  "template": {
    "id": "uuid",
    "user_id": "uuid",
    "title": "...",
    "content": "...",
    "tags": [],
    "is_public": false,
    "created_at": "...",
    "updated_at": "..."
  }
}

Example

curl
curl -X POST https://promptmia.com/api/templates \
  -H "Authorization: Bearer pt_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Customer Support Reply",
    "content": "Hi {{customer_name|text}},\n\nThank you for reaching out about {{issue|textarea:512|Describe the issue}}.\n\n{{resolution|textarea:512|Describe the resolution}}\n\nBest regards,\n{{agent_name|text}}",
    "tags": ["support", "email"],
    "is_public": false
  }'
GET/api/templates/:id

Get a single template by ID. Must be the owner.

Auth: API key or session

Response

{
  "template": { /* full Template object */ }
}
PUT/api/templates/:id

Update a template. All fields are optional — only provided fields are changed.

Auth: API key or session

Request body

NameTypeRequiredDescription
titlestringno1–255 chars
contentstringnoFull template content
descriptionstring | nullnoPass null to clear
tagsstring[]noReplaces the existing tag list
is_publicbooleannoPublish / unpublish

Response

{
  "template": { /* updated Template object */ }
}
DELETE/api/templates/:id

Permanently delete a template and all its associated share links.

Auth: API key or session

Response

{ "success": true }

Compile & Download

These are the primary endpoints for programmatic use. Authentication is always required; non-owners can access public templates with either an API key or a session.

POST/api/templates/:id/compile

Replace template variables with provided values and return the compiled string. Non-owners can compile public templates with valid credentials.

Auth: API key or session (non-owners may access public templates)

Request body

NameTypeRequiredDescription
variablesRecord<string, string>noMap of variable names to values. Missing variables become [name] placeholders.

Response

{
  "compiled": "Hi Alice, ...",
  "missing_variables": ["unset_field"]
}

Example

curl
curl -X POST https://promptmia.com/api/templates/{id}/compile \
  -H "Authorization: Bearer pt_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "variables": {
      "customer_name": "Alice",
      "issue": "billing discrepancy on invoice #1234",
      "resolution": "We have applied a credit to your account.",
      "agent_name": "Support Team"
    }
  }'

# Response:
# {
#   "compiled": "Hi Alice,\n\nThank you for reaching out about billing discrepancy on invoice #1234...",
#   "missing_variables": []
# }
GET/api/templates/:id/download

Download the template as a .md file. Supports compiled output with optional variable values. Non-owners can download public templates with valid credentials.

Auth: API key or session (non-owners may access public templates)

Query parameters

NameTypeRequiredDescription
format'raw' | 'compiled'noDefault: compiled. Use raw to download the template source.
variablesstring (base64 JSON)noBase64-encoded JSON object of variable values, e.g. btoa(JSON.stringify({name: 'Alice'}))

Response

Returns text/markdown with Content-Disposition: attachment; filename="..."

Example

curl
# Download compiled .md file
curl "https://promptmia.com/api/templates/{id}/download?format=compiled&variables=$(printf '{"name":"Alice"}' | base64)" \
  -H "Authorization: Bearer pt_your_api_key_here" \
  --output compiled-prompt.md

Public Templates

These endpoints do not require authentication and are suitable for embedding or discovery.

GET/api/templates/public

Browse publicly listed templates with search, tag filtering, sorting, and pagination.

Auth: None

Query parameters

NameTypeRequiredDescription
qstringnoFull-text search on title and description
tagstringnoFilter by a single tag (exact match)
authorstring (userId)noFilter by author's user ID
sort'newest' | 'oldest'noDefault: newest
pagenumbernoPage number, default 1. Page size is 18.

Response

{
  "templates": [
    {
      "id": "uuid",
      "title": "...",
      "description": "...",
      "content": "...",
      "tags": ["support"],
      "created_at": "...",
      "author": {
        "id": "uuid",
        "display_name": "Alice",
        "username": "alice",
        "avatar_url": "..."
      }
    }
  ],
  "total": 42,
  "page": 1,
  "page_size": 18,
  "total_pages": 3
}

Example

curl
curl "https://promptmia.com/api/templates/public?q=customer+support&tag=email&sort=newest&page=1"
GET/api/templates/:id/public

Fetch a single public template by ID. Returns 404 for private templates.

Auth: None

Response

{
  "template": {
    "id": "uuid",
    "title": "...",
    "description": "...",
    "content": "...",
    "tags": [],
    "created_at": "..."
  }
}

Example

curl
curl https://promptmia.com/api/templates/{id}/public

Share Links

Share links let you send a pre-filled template to anyone — no account required for the recipient. Links can carry pre-set variable values and optionally expire.

POST/api/templates/:id/share

Create a new share link for a template. The link URL is returned in the response.

Auth: API key or session (must be template owner)

Request body

NameTypeRequiredDescription
prefilled_variablesRecord<string, string>noVariable values pre-loaded when the recipient opens the link
expires_in_hoursnumber (1–8760)noHours until the link expires. Omit for no expiry.

Response

{
  "token": "ab12cd34...",
  "share_url": "https://promptmia.com/share/ab12cd34...",
  "expires_at": "2026-03-10T12:00:00Z"
}

Example

curl
curl -X POST https://promptmia.com/api/templates/{id}/share \
  -H "Authorization: Bearer pt_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "prefilled_variables": { "customer_name": "Alice", "agent_name": "Support Team" },
    "expires_in_hours": 72
  }'

# Response:
# {
#   "token": "ab12cd34...",
#   "share_url": "https://promptmia.com/share/ab12cd34...",
#   "expires_at": "2026-03-10T12:00:00Z"
# }
GET/api/templates/:id/shares

List all active (non-expired) share links for a template.

Auth: API key or session (must be template owner)

Response

{
  "shares": [
    {
      "id": "uuid",
      "token": "ab12cd34...",
      "share_url": "https://promptmia.com/share/ab12cd34...",
      "prefilled_variables": { "customer_name": "Alice" },
      "expires_at": "2026-03-10T12:00:00Z",
      "created_at": "..."
    }
  ]
}
PUT/api/templates/:id/shares/:shareId

Update the prefilled variable values for an existing share link. The share URL and token remain unchanged.

Auth: API key or session (must be template owner)

Request body

NameTypeRequiredDescription
prefilled_variablesRecord<string, string>yesNew set of prefilled values (replaces existing)

Response

{ "success": true }
DELETE/api/templates/:id/shares/:shareId

Revoke a share link. The token immediately becomes invalid.

Auth: API key or session (must be template owner)

Response

{ "success": true }
GET/api/share/:token

Resolve a share token — returns the template content and any prefilled variable values. Returns 410 if the link has expired.

Auth: None

Response

{
  "template": {
    "id": "uuid",
    "title": "...",
    "description": "...",
    "content": "...",
    "tags": []
  },
  "prefilled_variables": { "customer_name": "Alice" },
  "expires_at": "2026-03-10T12:00:00Z"
}

Example

curl
curl https://promptmia.com/api/share/{token}
GET/api/shares

List all share links across all of the authenticated user's templates. Includes an is_expired flag for easy filtering. Optionally filter by template_id.

Auth: Session only

Query parameters

NameTypeRequiredDescription
template_idstring (uuid)noFilter shares for a specific template

Response

{
  "shares": [
    {
      "id": "uuid",
      "token": "ab12cd34...",
      "share_url": "https://promptmia.com/share/ab12cd34...",
      "prefilled_variables": { "customer_name": "Alice" },
      "expires_at": "2026-03-10T12:00:00Z",
      "created_at": "...",
      "is_expired": false,
      "template": { "id": "uuid", "title": "Customer Support Reply" }
    }
  ]
}

API Keys

API keys are managed in Settings. These endpoints require a browser session — they are not callable via API key auth (to prevent recursion and key-created-key escalation).

Key format: All keys begin with pt_ followed by 64 hex characters. The raw key is shown once at creation time. Store it securely — it cannot be retrieved again.
GET/api/keys

List all API keys for the authenticated user. Key hashes are never returned.

Auth: Session only

Response

{
  "keys": [
    {
      "id": "uuid",
      "name": "my-agent-key",
      "key_prefix": "abcd1234",
      "last_used": "2026-03-01T00:00:00Z",
      "created_at": "..."
    }
  ]
}
POST/api/keys

Create a new API key. The raw key is returned once and never again — save it immediately.

Auth: Session only

Request body

NameTypeRequiredDescription
namestringyesFriendly label for the key (1–100 chars)

Response

{
  "api_key": {
    "id": "uuid",
    "name": "my-agent-key",
    "key_prefix": "abcd1234",
    "created_at": "..."
  },
  "raw_key": "pt_abcd1234ef567890..."  // save this — shown once only
}

Example

curl
curl -X POST https://promptmia.com/api/keys \
  -H "Content-Type: application/json" \
  -H "Cookie: <your-session-cookie>" \
  -d '{"name": "my-agent-key"}'

# Response:
# {
#   "api_key": { "id": "...", "name": "my-agent-key", "key_prefix": "abcd1234", "created_at": "..." },
#   "raw_key": "pt_abcd1234..."  ← save this, shown once only
# }
DELETE/api/keys/:id

Revoke an API key by its ID. Any requests using the revoked key will immediately receive 401.

Auth: Session only

Response

{ "success": true }

Profile

GET/api/profile

Get the authenticated user's own profile including email.

Auth: Session only

Response

{
  "profile": {
    "id": "uuid",
    "display_name": "Alice Smith",
    "username": "alice",
    "avatar_url": "...",
    "bio": "...",
    "email": "[email protected]",
    "created_at": "..."
  }
}
PUT/api/profile

Update the authenticated user's profile.

Auth: Session only

Request body

NameTypeRequiredDescription
display_namestringno1–80 chars
biostringnoMax 300 chars
usernamestring | nullno3–30 chars, lowercase letters, numbers, underscores only. Pass null to clear.

Response

{
  "profile": { /* updated profile object */ }
}
GET/api/profile/:userId

Get a public profile by user ID, along with their public templates. No email is returned.

Auth: None

Response

{
  "profile": {
    "id": "uuid",
    "display_name": "Alice Smith",
    "username": "alice",
    "avatar_url": "...",
    "bio": "...",
    "created_at": "..."
  },
  "templates": [ /* public templates */ ]
}
GET/api/u/:username

Get a public profile and their public templates by username.

Auth: None

Response

{
  "profile": { "id": "...", "display_name": "...", "username": "alice", ... },
  "templates": [ /* public templates */ ]
}

Error Handling

All errors return a JSON object with a statusMessage field and the appropriate HTTP status code. Stack traces are never included in responses.

StatusMeaning
400Invalid request body or query parameters (Zod validation failed)
401Missing or invalid authentication (no session, bad or unknown API key)
403Authenticated but not authorized (e.g. accessing another user's template)
404Resource not found
409Conflict — e.g. username already taken
410Gone — share link has expired
429Rate limit exceeded (AI endpoints: 10 req/min per user)
500Internal server error — retry with backoff
# Example error response
HTTP/1.1 401 Unauthorized
Content-Type: application/json

{
  "statusCode": 401,
  "statusMessage": "Invalid API key"
}

LLMs.txt

A condensed plain-text reference designed to be pasted into an LLM system prompt or agent context window. Also available as a static file you can fetch directly:

https://promptmia.com/llms.txtOpen ↗
LLMs.txt content (copy into system prompt)
# PromptMia API — Machine-Readable Reference

Base URL: https://promptmia.com
Auth:     Bearer {api_key}     (header: Authorization)
          Session cookie       (browser only — no header needed)

## Core workflow for LLM agents
1. POST /api/auth/login          → obtains session (or use pre-generated API key)
2. POST /api/templates           → create a template
3. POST /api/templates/{id}/compile → compile with variable values → get plain text
4. GET  /api/templates           → list owned templates
5. GET  /api/templates/public    → browse public templates (no auth)

## Template endpoints  (auth: API key or session)

POST /api/templates
  Body:    { title: string, content: string, tags?: string[], description?: string, is_public?: bool }
  Returns: { template: { id, user_id, title, content, tags, is_public, created_at, updated_at } }

GET /api/templates
  Returns: { templates: Template[] }

GET /api/templates/{id}
  Returns: { template: Template }

PUT /api/templates/{id}
  Body:    { title?, content?, tags?, description?, is_public? }
  Returns: { template: Template }

DELETE /api/templates/{id}
  Returns: { success: true }

## Compile & Download  (auth: API key or session — non-owners may access public templates)

POST /api/templates/{id}/compile
  Body:    { variables: Record<string,string> }
  Returns: { compiled: string, missing_variables: string[] }

GET /api/templates/{id}/download?format=raw|compiled&variables={base64-json}
  Returns: text/markdown file attachment

## Public templates  (no auth required)

GET /api/templates/public?q={search}&tag={tag}&author={userId}&sort=newest|oldest&page={n}
  Returns: { templates: Template[], total, page, page_size, total_pages }

GET /api/templates/{id}/public
  Returns: { template: { id, title, description, content, tags, created_at } }

## Share links  (auth: API key or session — must be template owner, except GET /api/share/{token})

POST /api/templates/{id}/share
  Body:    { prefilled_variables?: Record<string,string>, expires_in_hours?: number }
  Returns: { token: string, share_url: string, expires_at?: string }

GET /api/templates/{id}/shares
  Returns: { shares: [{ id, token, share_url, prefilled_variables, expires_at, created_at }] }

PUT /api/templates/{id}/shares/{shareId}
  Body:    { prefilled_variables: Record<string,string> }
  Returns: { success: true }

DELETE /api/templates/{id}/shares/{shareId}
  Returns: { success: true }

GET /api/share/{token}           (no auth required)
  Returns: { template: { id, title, description, content, tags }, prefilled_variables: Record<string,string>, expires_at?: string }

GET /api/shares                  (auth: session only)
  Query:   template_id? (optional filter)
  Returns: { shares: [{ id, token, share_url, prefilled_variables, expires_at, created_at, is_expired: bool, template: { id, title } }] }

## API Keys  (auth: session only — cannot be managed via API key)

GET /api/keys
  Returns: { keys: [{ id, name, key_prefix, last_used, created_at }] }

POST /api/keys
  Body:    { name: string }
  Returns: { api_key: { id, name, key_prefix, created_at }, raw_key: string }  <- raw_key shown once

DELETE /api/keys/{id}
  Returns: { success: true }

## Profile  (GET/PUT own profile: session only; GET by userId or username: no auth)

GET /api/profile                 (session only)
  Returns: { profile: { id, display_name, username, avatar_url, bio, email, created_at } }

PUT /api/profile                 (session only)
  Body:    { display_name?, bio?, username? }
  Returns: { profile: { ... } }

GET /api/profile/{userId}        (no auth)
  Returns: { profile: { id, display_name, username, avatar_url, bio, created_at }, templates: Template[] }

GET /api/u/{username}            (no auth)
  Returns: { profile: { id, display_name, username, avatar_url, bio, created_at }, templates: Template[] }

## Variable syntax in template content
  {{name}}                           text field, max 128 chars
  {{name|text}}                      explicit text type
  {{name|textarea:512}}              textarea, max 512 chars
  {{name|number}}                    numeric input
  {{name|email}}                     email input
  {{name|phone}}                     phone input
  {{name|list}}                      comma-separated list
  {{name|type:maxLength|description}} full form: all three segments

## API Key format
  All API keys start with 'pt_' followed by 64 hex characters.
  Keys are hashed server-side. The raw key is shown once on creation.
  Create keys at: https://promptmia.com/settings