API Integration
PromptCanvas API Documentation
Connect your application to PromptCanvas via REST API. Choose your preferred language to get started.
1
Installation
Set up your environment to access the PromptCanvas API.
bash
# No SDK required - use fetch or axios2
Setup
Initialize your API client with authentication.
javascript
const API_BASE = 'https://your-project.supabase.co/functions/v1/sdk';
const API_KEY = 'your_api_key_here';
// Using fetch
async function getPrompt(templateName, variables = {}) {
const response = await fetch(`${API_BASE}/prompts/${templateName}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
},
body: JSON.stringify({ variables })
});
const data = await response.json();
return data.result;
}
// Using axios
import axios from 'axios';
const client = axios.create({
baseURL: API_BASE,
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
});
async function getPrompt(templateName, variables = {}) {
const { data } = await client.post(`/prompts/${templateName}`, {
variables
});
return data.result;
}3
Usage
Start fetching and using prompts in your application.
javascript
// Fetch a prompt
const welcome = await getPrompt('welcome-email', {
name: 'Alice',
plan: 'premium'
});
console.log(welcome);
// "Welcome Alice! Thank you for choosing our premium plan."
// List all prompts
async function listPrompts() {
const response = await fetch(`${API_BASE}/prompts`, {
headers: { 'x-api-key': API_KEY }
});
return await response.json();
}
// Error handling
try {
const prompt = await getPrompt('non-existent');
} catch (error) {
if (error.response?.status === 404) {
console.log('Prompt not found');
}
}API Features
RESTful API
Works with any HTTP client
JSON responses
Error handling
No dependencies required
API Reference
POST /prompts/{template}
Fetch a formatted prompt template with variables.
Headers:
x-api-key: your_api_keyContent-Type: application/jsonBody:
{
"variables": {
"name": "Alice",
"plan": "premium"
}
}GET /prompts
List all available prompt templates.
Headers:
x-api-key: your_api_keyPull Prompts Locally
Store prompts as local files for offline access and version control
Offline Development
No network dependency, zero latency
Version Control
Track prompt changes in git
bash
# Initialize config
npx promptcanvas init
# Pull a specific prompt
npx promptcanvas pull system-prompt
# Pull all production prompts
npx promptcanvas pull --all
# List available prompts
npx promptcanvas listUse local prompts in your code:
typescript
import { LocalPrompts } from '@promptcanvas/sdk';
// Load prompts from local files
const prompts = new LocalPrompts({ dir: './prompts' });
// Get a prompt (no API call needed)
const systemPrompt = prompts.get('system-prompt');
console.log(systemPrompt.content);
// With variables
const welcome = prompts.get('welcome', { userName: 'John' });Python CLI:
python
# Install and use CLI
pip install promptcanvas
# Same commands work
promptcanvas init
promptcanvas pull --all
# Use local prompts
from promptcanvas import LocalPrompts
prompts = LocalPrompts(dir="./prompts")
content = prompts.get("system-prompt").content