Custom APIs & SDK: Infrastructure Made Easy
Aerostack lets you create your own custom APIs and run code with Database, Cache, AI, and more—backed by high-performance infrastructure—without deploying workers, binding Database/Cache/Queues, or managing config yourself. You get a simple wrapper over core primitives, scoped to your project.
Why This Matters
Using traditional serverless infrastructure, databases, and caches directly usually means:
- Deploying and maintaining your own serverless functions
- Configuring bindings and resources in complex configuration files
- Managing migrations, env vars, and secrets per environment
- Handling auth, rate limits, and project isolation yourself
With Aerostack Custom APIs and the Scoped SDK, you:
- Create APIs in the UI (Logic Lab): one endpoint per Logic Module, deploy instantly
- Or use AI to generate the code for you from a simple description
- Use Database, Cache, AI, Queue, Storage via a single
sdkobject—no config needed - Stay scoped: your code only sees your project’s data; automatic namespace isolation
- Get one URL per function: e.g.
POST /api/v1/public/projects/my-project/custom/search-products - Multi-language support: SDK available for JavaScript, Python, Go, PHP (more coming)
So you get the power of our optimized stack with minimal setup: write your logic, set a slug, and call your API.
Create Your Own Custom API
-
Logic Lab (Developer → Logic / Hooks): create a new Logic Module.
-
Type: choose Internal (script). Give it a Friendly name and an API slug (e.g.
search-products). -
Trigger: for a callable API, you can use Inbound API Request or any event; the custom URL is what external callers use.
-
Custom API URL (shown when type is Script and slug is set):
POST https://api.aerostack.dev/api/v1/public/projects/{projectSlug}/custom/{slug}You can enable GET and Public access (no API key) in the same screen.
-
Write your handler in the editor. You receive
sdkandevent; return a value and it becomes the JSON response.
Example: Custom Search API
/**
* @param {ISDK} sdk - Scoped Aerostack SDK (Database, Cache, AI, etc.)
* @param {object} event - { event, timestamp, data, project_id }
*/
export default async function(sdk, event) {
const { q, limit = 10 } = event.data || {};
const rows = await sdk.db.query(
"SELECT id, name, slug FROM products WHERE project_id = ? AND name LIKE ? LIMIT ?",
[event.project_id, `%${q || ''}%`, limit]
);
return { results: rows.results || [], count: (rows.results || []).length };
}Call it:
curl -X POST "https://api.aerostack.dev/api/v1/public/projects/my-project/custom/search-products" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"q":"shirt","limit":5}'You can create as many custom APIs as you need—each Logic Module with a slug gets its own endpoint.
💡 Tip: Use the AI API Generator to create APIs from plain English descriptions
The Aerostack Hook SDK: Infrastructure Made Easy
Inside your Logic Module (and other script hooks), you get a scoped SDK that wraps platform services. No complex bindings or config in your code.
Database
sdk.db.query(sql, params)– Run parameterized SQL against your project’s data (e.g. ecommerce/product tables). Queries are scoped by how the platform wires the DB; you use the same high-performance store as the rest of Aerostack.- Use for: search, filters, reports, custom aggregates, or any read/write your app needs.
Cache
sdk.cache.get(key)– Get a value (JSON-deserialized).sdk.cache.set(key, value, ttl?)– Set a value with optional TTL (seconds). Keys are automatically prefixed with your project so you never collide with other projects.- Use for: rate limiting, session-like data, expensive computed results, or feature flags.
AI Models
sdk.ai.chat(model, messages)– Access 30+ AI models for text generation, chat, embeddings, and more. No API keys or billing setup required.- Model Selection: Choose from optimized models like
@cf/meta/llama-3-8b-instruct,@cf/mistral/mistral-7b-instruct-v0.1, or@cf/openai/gpt-3.5-turbo - Use for: content moderation, summaries, classifications, sentiment analysis, chatbots, recommendations
Example:
const response = await sdk.ai.chat('@cf/meta/llama-3-8b-instruct', [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Classify this review as positive or negative: "Great product!"' }
]);
// Returns: {"sentiment": "positive"}HTTP
sdk.fetch(url, options?)– Call external APIs (with a standard User-Agent). Use for webhooks, third-party APIs, or posting to Slack/Discord.
Secrets
sdk.secrets.get(key)– Read a secret stored for your project (e.g. API keys for external services). No need to put secrets in your script code.
Queue
sdk.queue.enqueue(jobName, data)– Enqueue background jobs for async processing (e.g. email sending, data sync, image processing)- Jobs are executed automatically without setting up workers or consumers
- Built-in retry logic and error handling
- Use for: long-running tasks, async workflows, scheduled jobs
Example:
// In your API
await sdk.queue.enqueue('send-welcome-email', {
user_id: event.data.user_id,
email: event.data.email
});
// Queue worker (auto-registered)
export async function sendWelcomeEmail(sdk, job) {
const { user_id, email } = job.data;
// Fetch user details
const user = await sdk.db.query(
'SELECT * FROM users WHERE id = ?',
[user_id]
);
// Send email via external API
await sdk.fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'POST',
headers: {
'Authorization': `Bearer ${await sdk.secrets.get('SENDGRID_KEY')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
personalizations: [{ to: [{ email }] }],
from: { email: '[email protected]' },
subject: 'Welcome to Aerostack!',
content: [{ type: 'text/html', value: `<h1>Hi ${user.name}!</h1>` }]
})
});
}Summary
| What you get | Without Aerostack | With Aerostack Custom API + SDK |
|---|---|---|
| Custom API endpoint | Deploy infrastructure, define routes | Create Logic Module, set slug |
| Database | Create database, bindings, migrations | sdk.db.query(...) scoped to your project |
| Cache | Create cache, bindings | sdk.cache.get/set with project prefix |
| AI | Configure AI hardware / external API | sdk.ai.chat(...) |
| Secrets | Env vars / secrets in config | sdk.secrets.get(key) per project |
| Queue | Configure Queue, consumer Worker | Planned in SDK |
You focus on what your API should do; we handle the underlying wiring, scoping, and auth so you can ship custom APIs and use Database, Cache, AI, and more without the usual config.
For event-based hooks (e.g. User Signed Up, Order Created), see Hooks & Events Overview.