Validate & Test
Before deploying an algorithm, validate its syntax and test it against real data. This page covers the three endpoints that make up the authoring workflow: compose, validate, and test-run.
Workflow
Write code (or Compose)
│
POST /algo/validate ──→ signature + syntax_check + security_check
│
POST /run/algo ──→ sandbox execution, returns feed + logs
│
POST /deploy/algos ──→ save (requires valid signature)
The signature from validation is required for both test-run and saving. You cannot skip validation.
Compose: Generate from Natural Language
Generate algorithm code from a plain-English prompt:
curl -X POST https://api.mbd.xyz/v3/studio/algo/compose \
-H "Authorization: Bearer mbd-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Create a feed of trending Polymarket markets about crypto, personalized to the user trading history",
"version": "V1",
"feed_type": "algorithm",
"feed_inputs": "user_id"
}'Response
{
"result": {
"algorithm": "mbd.forUser(\"polymarket-wallets\", polymarketWallet);\nconst candidates = await mbd.search()...",
"summary": "This algorithm searches for active Polymarket crypto markets..."
}
}- algorithm — generated JavaScript code ready to validate and test
- summary — human-readable explanation of what the algorithm does
Parameters
| Parameter | Type | Description |
|---|---|---|
prompt | string | Natural language description of the feed you want |
version | string | SDK version. Use "V1" |
feed_type | string | "algorithm" (full StudioV1 pipeline) or "minifeed" (search-only) |
feed_inputs | string | "user_id" — the input variable available to the algorithm |
Validate: Check Syntax and Security
Validate algorithm code before testing or saving:
curl -X POST https://api.mbd.xyz/v3/studio/algo/validate \
-H "Authorization: Bearer mbd-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"algorithm": "const items = await search.index(\"farcaster-items\").include().term(\"lang\",\"en\").size(10).execute(); search.show(items);",
"version": "V1",
"feed_type": "minifeed",
"feed_inputs": "user_id"
}'Response
{
"result": {
"signature": "eyJhbGciOi...",
"syntax_check": true,
"security_check": true,
"syntax_message": "OK",
"security_message": "OK"
}
}- signature — JWT token required for test-run and saving. Encodes the validated code.
- syntax_check —
trueif the code parses correctly - security_check —
trueif no dangerous patterns detected - syntax_message / security_message — error details if checks fail
Important: The
signatureis tied to the exact algorithm code. If you change the code, you must re-validate to get a new signature.
Test Run: Execute in Sandbox
Run a validated algorithm against real data in a sandbox environment:
curl -X POST https://api.mbd.xyz/v3/studio/run/algo \
-H "Authorization: Bearer mbd-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"feed_type": "algorithm",
"feed_inputs": "user_id",
"algorithm": "mbd.forUser(\"polymarket-wallets\", polymarketWallet); const items = await mbd.search().index(\"polymarket-items\").include().term(\"active\", true).sortBy(\"volume_24hr\",\"desc\").size(10).execute(); mbd.addCandidates(items); return mbd.getFeed();",
"signature": "eyJhbGciOi...",
"farcasterFid": "16085",
"polymarketWallet": "0x1234...",
"return_log": true
}'Response
{
"result": {
"feed": [
{
"_id": "661295",
"_index": "polymarket-items",
"_source": { "question": "Will BTC reach $150k?" }
}
],
"logs": ["Using Algorithms DSL version V1", "Search returned 10 candidates"]
}
}- feed — the algorithm's output items
- logs — any
log()output from the algorithm code (only ifreturn_log: true)
Parameters
| Parameter | Type | Description |
|---|---|---|
feed_type | string | "algorithm" or "minifeed" (must match validation) |
feed_inputs | string | "user_id" (must match validation) |
algorithm | string | The algorithm code (must match what was validated) |
signature | string | The signature from /algo/validate |
farcasterFid | string | Optional Farcaster FID for personalization |
polymarketWallet | string | Optional wallet address for personalization |
return_log | boolean | Include log() output in response |
Sandbox Limits
- Timeout: 10 seconds
- Available objects:
mbd(StudioV1 instance) foralgorithmtype,search(Search instance) forminifeedtype - Available inputs:
farcasterFidandpolymarketWalletare injected as variables
Save: Deploy the Algorithm
Once validated and tested, save the algorithm:
curl -X POST https://api.mbd.xyz/v3/studio/deploy/algos \
-H "Authorization: Bearer mbd-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Polymarket Trending Crypto",
"description": "Trending crypto prediction markets personalized to user",
"feed_type": "algorithm",
"feed_inputs": "user_id",
"algorithm": "...",
"signature": "eyJhbGciOi...",
"is_public": false
}'This returns an algo_id you can use in Feed Configs.
What's Next
- Feed Configs → Bundle your algorithm into a deployable feed config
- Search → Deep dive into candidate generation
- API Reference: Validate — full endpoint spec
- API Reference: Test Run — full endpoint spec
Updated 10 days ago
