blocks-proxy
Skill42 starsChanged 12 days agoMITView on GitHub
Call a third-party API from app code without shipping its URL or keys: configure a Blocks Logic proxy with `blocks logic proxy *` (upstream, declared routes, injected headers with `{{$VAR.name}}` secrets, who-can-call access, timeout/retry/circuit breaker, rate limit, OpenAPI import), then call it with the SDK's `blocksClient.logic.proxy.request()`. Also covers testing, version history/revert and request logs. Use for credentialed upstream passthrough; custom code belongs in blocks-functions, event graphs in blocks-workflow.
- Reads credentials
In this repository27 other files it gives its agents.
- AGENTS.mdAGENTS.md
- bootstrap/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- blocks-bootstrapSkill
- blocks-captchaSkill
- blocks-data-gateway-configurationSkill
- blocks-data-gateway-crudSkill
- blocks-data-storageSkill
- blocks-frontend-local-httpsSkill
- blocks-functionsSkill
- blocks-iam-access-controlSkill
- blocks-iam-accountSkill
- blocks-iam-mfaSkill
- blocks-iam-organizationsSkill
- blocks-iam-sso-oidc-configurationSkill
- blocks-iam-sso-oidc-implementationSkill
- blocks-iam-usersSkill
- blocks-localization-configurationSkill
- blocks-localization-implementationSkill
- blocks-mailSkill
- blocks-notificationSkill
- blocks-notifierSkill
- blocks-release-deploymentSkill
- blocks-secretsSkill
- blocksSkill
- blocks-storage-configurationSkill
- blocks-workflowSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 6
When invoking a project-scoped blocks command, either use the resolved account's saved selection or pass --project <tenantId> for that one …
- Distinctive: line 54
Import routes from OpenAPI: instead of typing them:
- Very specific: line 67
Every update is checked against the version it was read from.
- Very specific: line 71
All writes take --dry-run first, then --yes after approval.
- Very specific: line 103
Never type a key into a header value: Use {{$VAR.<secretName>}}.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When invoking a project-scoped blocks command, either use the resolved account's saved selection or pass --project <tenantId> for that one command without changing saved state. --project applies to CLI commands only, never SDK calls.
Blocks Proxy
A proxy is a named gateway route in front of one upstream API. The app calls the proxy; Blocks checks who is calling, rebuilds the request against the stored upstream, adds the configured headers/query/body fields (resolving secrets server-side), forwards it, and logs the exchange. The browser never sees the upstream URL or its key.
- CLI —
blocks logic proxy *— configure, test, inspect, revert. No SDK equivalent. - SDK —
blocksClient.logic.proxy.*— call a configured proxy:request(),requestRaw(),url().
For CLI work, use blocks-bootstrap first when account or project context is unknown.
Local snapshot: blocks/logic/proxies.json (from blocks pull --only logic) lists the project's proxies with upstreams redacted. Read it before listing; check _meta.tenantId / _meta.pulledAt.
Configure
Simple proxy — one upstream, a few methods:
blocks logic proxy create --name "Weather" --upstream https://api.weather.example --methods GET --dry-run --json
blocks logic proxy create --name "Weather" --upstream https://api.weather.example --methods GET --yes --json # note "itemId" and "slug"Anything richer goes in a JSON body with --file (create) or as a full replacement (update):
{
"name": "Stripe",
"upstream": "https://api.stripe.com/v1",
"methods": ["GET", "POST"],
"headers": [{ "key": "Authorization", "value": "Bearer {{$VAR.STRIPE_SECRET_KEY}}" }],
"routes": [
{ "method": "GET", "path": "charges/{id}", "upstreamPath": "charges/{id}" },
{ "method": "POST", "path": "charges" }
],
"access": { "kind": "BlocksToken", "roles": { "mode": "any", "values": ["billing"] } },
"resilience": { "timeoutSeconds": 10, "retry": { "attempts": 2, "backoff": "Fixed", "initialDelaySeconds": 1, "idempotent": true }, "breaker": { "failureThreshold": 5, "openSeconds": 60 } },
"requestsPerMinute": 300
}upstream— absolutehttps://URL; no credentials in it (refused).routes[].upstreamPathrewrites the path;{name}segments must be declared inpath.routes— the only paths the proxy forwards. Omitted ⇒ only the base path, any suffix is refused. Each route may overrideheaders,query,bodyMerge,responseMode/responseIncludeandresilience.headers/query/bodyMerge—{ key, value }pairs added to every forward. Put credentials in as{{$VAR.<secretName>}}, a reference to a Blocks secret (create it with blocks-secrets first); it is resolved on each call, never stored or echoed, and masked in logs.responseMode: "Select"withresponseInclude: ["id", "amount"]returns only those response fields.access—kind: "BlocksToken"(default: any signed-in project user; narrow withroles/permissions{ mode: "any"|"all", values }andcombine: "Or"|"And") orkind: "Public"(only the project'sx-blocks-key; no role/permission lists allowed).resilience—timeoutSeconds1–30;retry.attempts1–3 (more than 1 requires"idempotent": true),backoffNone|Fixed|Exponential;breakeropens afterfailureThresholdfailures foropenSeconds.requestsPerMinute— 1–100000 across all callers; default 600 for Public, unlimited for token proxies.
Import routes from OpenAPI instead of typing them:
blocks logic proxy openapi-preview --spec-file openapi.json --json # or --spec-url https://…/openapi.json
blocks logic proxy openapi-preview --spec-file openapi.json --proxy-id <id> --json # flags routes the proxy already hasIt writes nothing — copy the operations you want into routes (method, path) of a create/update --file; securityHeaders names the auth headers the API expects, to fill with {{$VAR.…}} values.
Change
blocks logic proxy update <id> --name … | --upstream … | --methods … | --requests-per-minute <n|default> | --timeout-seconds <n>— read-merge-write: every other field (routes, headers, access, retry/breaker) is kept.blocks logic proxy update <id> --file proxy.json— full replacement: omittedaccess,resilience,requestsPerMinute,routes… reset to defaults. Start fromblocks logic proxy get <id> --jsonand edit.- Every update is checked against the version it was read from;
PROXY_VERSION_CONFLICTmeans someone changed it in between — re-read and apply again. enable/disable <id>— a disabled proxy answers 404 to callers.delete <id>— removes it; history and logs stay.versions <id>/revert <id> <versionId>— every change is a version; revert appends a new one.
All writes take --dry-run first, then --yes after approval.
Test and observe
blocks logic proxy test <id> --method GET --path-suffix charges/ch_1 [--query 'limit=1'] [--body '<json>']— calls the upstream through the saved config without logging an execution.--draft-file proxy.jsontests an unsaved config (including its resilience settings).blocks logic proxy executions <id> [--status-class 4xx|5xx]→execution <id> <executionId>— the last 24 h of real calls, secrets redacted.blocks logic proxy overview <id>— calls, latency, error rate.
SDK — calling a proxy
import { BlocksApiError } from "@seliseblocks/client";
import { blocksClient } from "../../lib/blocks/client";
const charge = await blocksClient.logic.proxy.request<{ id: string; amount: number }>("stripe", {
method: "GET",
path: "charges/ch_123",
query: { expand: ["customer"] }
});request(slug, options)— parsed response body; any non-2xx throwsBlocksApiError(error.status,error.body). The first argument is the proxy's slug (fromcreate/get), not its id.requestRaw(slug, options)— the unreadResponse, for files/streams or whenRetry-Aftermatters.url(slug, path?)— absolute gateway URL for other backends.- Options:
method(default GET),path,query,body(JSON unless already aBodyInit),headers,auth(default true;falsefor a Public proxy called without a session),signal.
Gateway refusals carry PROXY_GATEWAY_<OUTCOME> codes in error.body.code: 401 no/invalid token, 403 access rules or a path no route declares, 404 unknown or disabled proxy, 405 method not allowed, 413 body over 1 MB, 429 rate limit (Retry-After), 502/503/504 upstream error/unavailable/timeout. Upstream responses over 5 MB are refused.
Gotchas
- Slug for calls, id for configuration. SDK calls take the slug; every CLI command takes the
itemId. - A path suffix must match a declared route. A proxy without
routesforwards only its base path. - Never type a key into a header value. Use
{{$VAR.<secretName>}}; the literal would be stored and shown to anyone who can read the proxy. update --filereplaces everything; use the flag form for small changes.- Retries need
"idempotent": true— the platform will not replay a request it cannot assume is safe to repeat. - A workflow can call a proxy with its
proxystep (see blocks-workflow); app code uses the SDK.
Example trigger prompts
- "Call the weather API from the frontend without exposing our key." → blocks-secrets for the key,
proxy create --filewithheaders: [{ key: "X-Api-Key", value: "{{$VAR.WEATHER_KEY}}" }]and the routes, thenblocksClient.logic.proxy.request("weather", …). - "Import the routes from their OpenAPI spec." →
blocks logic proxy openapi-preview --spec-url <url> --json, thencreate/update --file. - "Only billing admins may use the Stripe proxy." →
get <id> --json, setaccess.roles,update <id> --file. - "The upstream is flaky." →
update <id> --timeout-seconds 10, plusretry/breakerthrough--file. - "Why are calls failing?" →
blocks logic proxy executions <id> --status-class 5xx --json, thenexecution <id> <executionId>.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

