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

ParameterTypeDescription
promptstringNatural language description of the feed you want
versionstringSDK version. Use "V1"
feed_typestring"algorithm" (full StudioV1 pipeline) or "minifeed" (search-only)
feed_inputsstring"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_checktrue if the code parses correctly
  • security_checktrue if no dangerous patterns detected
  • syntax_message / security_message — error details if checks fail

Important: The signature is 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 if return_log: true)

Parameters

ParameterTypeDescription
feed_typestring"algorithm" or "minifeed" (must match validation)
feed_inputsstring"user_id" (must match validation)
algorithmstringThe algorithm code (must match what was validated)
signaturestringThe signature from /algo/validate
farcasterFidstringOptional Farcaster FID for personalization
polymarketWalletstringOptional wallet address for personalization
return_logbooleanInclude log() output in response

Sandbox Limits

  • Timeout: 10 seconds
  • Available objects: mbd (StudioV1 instance) for algorithm type, search (Search instance) for minifeed type
  • Available inputs: farcasterFid and polymarketWallet are 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