API Examples
All examples assume Fabric is running at https://gofabric.dev. Replace placeholder IDs with actual values from your environment.
import { FabricClient } from "@fabric-platform/sdk";const fabric = new FabricClient({ apiKey: "fab_xxx" });from fabric_platform import FabricClientfabric = FabricClient(api_key="fab_xxx")use fabric_sdk::FabricClient;let client = FabricClient::new("https://gofabric.dev", "fab_xxx")?;export FABRIC_API_KEY="fab_xxx"export FABRIC_URL="https://gofabric.dev"# All curl examples below use these variablesSystem
Section titled “System”const health = await fabric.healthCheck();const providers = await fabric.listProviders();health = fabric.health_check()providers = fabric.list_providers()let health = client.health_check().await?;let providers = client.list_providers().await?;# Health checkcurl $FABRIC_URL/healthz
# Readiness checkcurl $FABRIC_URL/readyz
# OpenAPI speccurl $FABRIC_URL/openapi.jsonIdentity
Section titled “Identity”// Get current principalconst me = await fabric.getMe();
// List my organizationsconst orgs = await fabric.getMyOrganizations();
// List my teamsconst teams = await fabric.getMyTeams();
// Get my effective permissionsconst perms = await fabric.getMyPermissions();# Get current principalme = fabric.get_me()
# List my organizationsorgs = fabric.get_my_organizations()
# List my teamsteams = fabric.get_my_teams()
# Get my effective permissionsperms = fabric.get_my_permissions()// Get current principallet me = client.get_me().await?;
// List my organizationslet orgs = client.get_my_organizations().await?;
// List my teamslet teams = client.get_my_teams().await?;
// Get my effective permissionslet perms = client.get_my_permissions().await?;# Get current principalcurl -H "Authorization: Bearer $FABRIC_API_KEY" $FABRIC_URL/v1/me
# List my organizationscurl -H "Authorization: Bearer $FABRIC_API_KEY" $FABRIC_URL/v1/me/organizations
# List my teamscurl -H "Authorization: Bearer $FABRIC_API_KEY" $FABRIC_URL/v1/me/teams
# Get my effective permissionscurl -H "Authorization: Bearer $FABRIC_API_KEY" $FABRIC_URL/v1/me/permissionsTenancy
Section titled “Tenancy”// Create an organizationconst org = await fabric.createOrganization({ slug: "acme", name: "Acme Corp",});
// Get organization detailsconst orgDetails = await fabric.getOrganization("<org-id>");
// List organization teamsconst teams = await fabric.listTeams("<org-id>");
// List organization membersconst members = await fabric.listMembers("<org-id>");
// Create a teamconst team = await fabric.createTeam({ organizationId: "<org-id>", slug: "engineering", name: "Engineering",});
// Create an invitationconst invite = await fabric.createInvitation({ organizationId: "<org-id>", email: "user@example.com", role: "member",});# Create an organizationorg = fabric.create_organization(slug="acme", name="Acme Corp")
# Get organization detailsorg_details = fabric.get_organization("<org-id>")
# List organization teamsteams = fabric.list_teams("<org-id>")
# List organization membersmembers = fabric.list_members("<org-id>")
# Create a teamteam = fabric.create_team( organization_id="<org-id>", slug="engineering", name="Engineering",)
# Create an invitationinvite = fabric.create_invitation( organization_id="<org-id>", email="user@example.com", role="member",)// Create an organizationlet org = client.create_organization("acme", "Acme Corp").await?;
// Get organization detailslet org_details = client.get_organization("<org-id>").await?;
// List organization teamslet teams = client.list_teams("<org-id>").await?;
// List organization memberslet members = client.list_members("<org-id>").await?;
// Create a teamlet team = client.create_team("<org-id>", "engineering", "Engineering").await?;
// Create an invitationlet invite = client.create_invitation("<org-id>", "user@example.com", "member").await?;# Create an organizationcurl -X POST $FABRIC_URL/v1/organizations \ -H 'content-type: application/json' \ -d '{"slug":"acme","name":"Acme Corp"}'
# Get organization detailscurl $FABRIC_URL/v1/organizations/<org-id>
# List organization teamscurl $FABRIC_URL/v1/organizations/<org-id>/teams
# List organization memberscurl $FABRIC_URL/v1/organizations/<org-id>/members
# Create a teamcurl -X POST $FABRIC_URL/v1/teams \ -H 'content-type: application/json' \ -d '{"organization_id":"<org-id>","slug":"engineering","name":"Engineering"}'
# Create an invitationcurl -X POST $FABRIC_URL/v1/invitations \ -H 'content-type: application/json' \ -d '{"organization_id":"<org-id>","email":"user@example.com","role":"member"}'Authorization
Section titled “Authorization”// Single permission checkconst allowed = await fabric.checkPermission({ resource: `organization:${orgId}`, action: "invite",});
// Batch permission checkconst results = await fabric.checkPermissions([ { resource: `organization:${orgId}`, action: "read" }, { resource: `team:${teamId}`, action: "create" },]);# Single permission checkallowed = fabric.check_permission("invite", resource=f"organization:{org_id}")
# Batch permission checkresults = fabric.check_permissions([ {"resource": f"organization:{org_id}", "action": "read"}, {"resource": f"team:{team_id}", "action": "create"},])// Single permission checklet allowed = client.check_permission("invite", Some(&format!("organization:{org_id}"))).await?;
// Batch permission checklet results = client.check_permissions(vec![ json!({"resource": format!("organization:{org_id}"), "action": "read"}), json!({"resource": format!("team:{team_id}"), "action": "create"}),]).await?;# Single permission checkcurl -X POST $FABRIC_URL/v1/authz/check \ -H 'content-type: application/json' \ -d '{"resource":"organization:<org-id>","action":"invite"}'
# Batch permission checkcurl -X POST $FABRIC_URL/v1/authz/check-batch \ -H 'content-type: application/json' \ -d '{"checks":[{"resource":"organization:<org-id>","action":"read"},{"resource":"team:<team-id>","action":"create"}]}'// Submit a jobconst job = await fabric.createJob({ modality: "image", tier: "premium", input: { prompt: "a cat in space" }, params: { size: "1024x1024" }, organizationId: "<org-id>",});
// Submit with idempotency keyconst job2 = await fabric.createJob({ modality: "text", input: { prompt: "Hello world" }, organizationId: "<org-id>", idempotencyKey: "unique-request-id-123",});
// Get job statusconst status = await fabric.getJob("<job-id>");
// List jobsconst jobs = await fabric.listJobs();
// Get job usageconst usage = await fabric.getJobUsage("<job-id>");# Submit a jobjob = fabric.create_job( modality="image", tier="premium", input={"prompt": "a cat in space"}, params={"size": "1024x1024"}, organization_id="<org-id>",)
# Submit with idempotency keyjob2 = fabric.create_job( modality="text", input={"prompt": "Hello world"}, organization_id="<org-id>", idempotency_key="unique-request-id-123",)
# Get job statusstatus = fabric.get_job("<job-id>")
# List jobsjobs = fabric.list_jobs()
# Get job usageusage = fabric.get_job_usage("<job-id>")// Submit a joblet job = client.create_job(serde_json::json!({ "modality": "image", "tier": "premium", "input": {"prompt": "a cat in space"}, "params": {"size": "1024x1024"}, "organization_id": "<org-id>"})).await?;
// Get job statuslet status = client.get_job("<job-id>").await?;
// List jobslet jobs = client.list_jobs().await?;
// Get job usagelet usage = client.get_job_usage("<job-id>").await?;# Submit a jobcurl -X POST $FABRIC_URL/v1/jobs \ -H 'content-type: application/json' \ -d '{ "modality": "image", "tier": "premium", "input": {"prompt": "a cat in space"}, "params": {"size": "1024x1024"}, "organization_id": "<org-id>" }'
# Submit with idempotency keycurl -X POST $FABRIC_URL/v1/jobs \ -H 'content-type: application/json' \ -d '{ "modality": "text", "input": {"prompt": "Hello world"}, "organization_id": "<org-id>", "idempotency_key": "unique-request-id-123" }'
# Get job statuscurl $FABRIC_URL/v1/jobs/<job-id>
# List jobscurl $FABRIC_URL/v1/jobs
# Get job usagecurl $FABRIC_URL/v1/jobs/<job-id>/usageWorkflows
Section titled “Workflows”import { WorkflowBuilder } from "@fabric-platform/sdk";
// Create a workflow definitionconst workflow = new WorkflowBuilder("transcribe-and-summarize") .node("transcribe", "ai_invoke", (n) => n.config({ operation: "audio.transcribe", modality: "audio" }) ) .node("summarize", "ai_invoke", (n) => n.dependsOn("transcribe") .config({ operation: "ai.generate", modality: "text" }) ) .build();
const defId = await fabric.registerDefinition(workflow);
// Create and runconst result = await fabric.runDefinition(workflow, { context: { audio: { url: "https://example.com/audio.wav" } },});
// Or step by step:const runId = await fabric.runWorkflow(defId, { audio: { url: "https://example.com/audio.wav" },});
// Start executionawait fabric.startRun(runId);
// Cancel if neededawait fabric.cancelRun(runId);# Create a workflow definitionwf_id = fabric.upsert_workflow("transcribe-and-summarize", nodes=[ { "key": "transcribe", "operation": "audio.transcribe", "runtime": "provider", "config": {"modality": "audio"}, }, { "key": "summarize", "operation": "ai.generate", "runtime": "provider", "depends_on": ["transcribe"], "config": {"modality": "text"}, },])
# Create a runrun_id = fabric.run_workflow(wf_id, context={ "audio": {"url": "https://example.com/audio.wav"},})
# Wait for completionresult = fabric.wait_for_run(run_id)
# Cancel if neededfabric.cancel_run(run_id)// Create a workflow definitionlet wf_id = client.upsert_workflow("transcribe-and-summarize", serde_json::json!({ "nodes": [ {"key": "transcribe", "operation": "audio.transcribe", "runtime": "provider"}, {"key": "summarize", "operation": "ai.generate", "runtime": "provider", "depends_on": ["transcribe"]} ]})).await?;
// Create a runlet run_id = client.run_workflow(wf_id, serde_json::json!({ "audio": {"url": "https://example.com/audio.wav"}})).await?;
// Wait for completionlet result = client.wait_for_run(run_id).await?;# Create a workflow definitioncurl -X POST $FABRIC_URL/v1/workflow-definitions \ -H 'content-type: application/json' \ -d '{ "name": "transcribe-and-summarize", "organization_id": "<org-id>", "nodes": [ {"key":"transcribe","operation":"audio.transcribe","runtime":"provider","config":{"modality":"audio"}}, {"key":"summarize","operation":"ai.generate","runtime":"provider","depends_on":["transcribe"],"config":{"modality":"text"}} ] }'
# Create a workflow runcurl -X POST $FABRIC_URL/v1/workflow-runs \ -H 'content-type: application/json' \ -d '{"workflow_definition_id":"<definition-id>","context":{"audio":{"url":"https://example.com/audio.wav"}}}'
# Start a workflow runcurl -X POST $FABRIC_URL/v1/workflow-runs/<run-id>/start
# Cancel a workflow runcurl -X POST $FABRIC_URL/v1/workflow-runs/<run-id>/cancelFace Swap & Motion Transfer
Section titled “Face Swap & Motion Transfer”// Face swap — swap a persona onto a source imageconst run = await fabric.workflows.runs.submitAndWait("video/face-swap", { input: { source_url: "https://example.com/dance-still.jpg", target_url: "https://example.com/persona-face.png", },});
// Motion transfer — animate a persona with a reference videoconst run = await fabric.workflows.runs.submitAndWait("video/motion-transfer", { input: { source_image_url: "https://example.com/persona.png", driving_video_url: "https://example.com/dance-reference.mp4", },});
// Pull persona from org gallery instead of direct URLconst run = await fabric.workflows.runs.submitAndWait("video/face-swap", { input: { source_url: "https://example.com/trending-video-frame.jpg", persona_gallery_id: "gallery-uuid", },});# Face swapresult = fabric.face_swap( source_url="https://example.com/dance-still.jpg", target_url="https://example.com/persona-face.png",)
# Motion transferresult = fabric.motion_transfer( driving_video_url="https://example.com/dance-reference.mp4", source_image_url="https://example.com/persona.png",)
# Pull persona from org galleryresult = fabric.face_swap( source_url="https://example.com/trending-frame.jpg", persona_gallery_id="gallery-uuid",)// Face swaplet result = client.face_swap( "https://example.com/dance-still.jpg", Some("https://example.com/persona-face.png"), None,).await?;
// Motion transferlet result = client.motion_transfer( "https://example.com/dance-reference.mp4", Some("https://example.com/persona.png"), None, None,).await?;
// Pull persona from org gallerylet result = client.face_swap( "https://example.com/trending-frame.jpg", None, Some("gallery-uuid"),).await?;# Face swapcurl -X POST "$FABRIC_URL/v1/workflows/run?name=video/face-swap" \ -H "Authorization: Bearer $FABRIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "input": { "source_url": "https://example.com/dance-still.jpg", "target_url": "https://example.com/persona-face.png" } }'
# Motion transfercurl -X POST "$FABRIC_URL/v1/workflows/run?name=video/motion-transfer" \ -H "Authorization: Bearer $FABRIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "input": { "source_image_url": "https://example.com/persona.png", "driving_video_url": "https://example.com/dance-reference.mp4" } }'Providers
Section titled “Providers”// List available providersconst providers = await fabric.listProviders();
// Execute a provider requestconst result = await fabric.executeProvider({ modality: "text", model: "qwen3:latest", input: { prompt: "Explain quantum computing in one sentence" }, params: { temperature: 0.7 },});
// Estimate costconst estimate = await fabric.estimateCost({ modality: "text", model: "gpt-4", input: { prompt: "Hello world" },});# List available providersproviders = fabric.list_providers()
# Execute a provider requestresult = fabric.execute_provider( modality="text", model="qwen3:latest", input={"prompt": "Explain quantum computing in one sentence"}, params={"temperature": 0.7},)
# Estimate costestimate = fabric.estimate_cost( modality="text", model="gpt-4", input={"prompt": "Hello world"},)// List available providerslet providers = client.list_providers().await?;
// Execute a provider requestlet result = client.execute_provider(serde_json::json!({ "modality": "text", "model": "qwen3:latest", "input": {"prompt": "Explain quantum computing in one sentence"}, "params": {"temperature": 0.7}})).await?;
// Estimate costlet estimate = client.estimate_cost(serde_json::json!({ "modality": "text", "model": "gpt-4", "input": {"prompt": "Hello world"}})).await?;# List available providerscurl $FABRIC_URL/v1/providers
# Execute a provider requestcurl -X POST $FABRIC_URL/v1/providers/execute \ -H 'content-type: application/json' \ -d '{ "modality": "text", "model": "qwen3:latest", "input": {"prompt": "Explain quantum computing in one sentence"}, "params": {"temperature": 0.7} }'
# Stream a provider response (SSE)curl -N -X POST $FABRIC_URL/v1/providers/execute/stream \ -H 'content-type: application/json' \ -d '{ "modality": "text", "model": "qwen3:latest", "input": {"prompt": "Write a haiku about Rust"}, "params": {"stream": true} }'
# Estimate costcurl -X POST $FABRIC_URL/v1/providers/estimate \ -H 'content-type: application/json' \ -d '{"modality":"text","model":"gpt-4","input":{"prompt":"Hello world"}}'API Keys
Section titled “API Keys”// Create an API keyconst key = await fabric.createApiKey({ name: "my-service-key", organizationId: "<org-id>", scopes: ["jobs:write", "providers:execute"],});console.log("Store this key:", key.raw_key);
// List API keysconst keys = await fabric.listApiKeys();
// Revoke an API keyawait fabric.deleteApiKey("<key-id>");# Create an API keykey = fabric.create_api_key( name="my-service-key", organization_id="<org-id>", scopes=["jobs:write", "providers:execute"],)print("Store this key:", key["raw_key"])
# List API keyskeys = fabric.list_api_keys()
# Revoke an API keyfabric.delete_api_key("<key-id>")// Create an API keylet key = client.create_api_key(serde_json::json!({ "name": "my-service-key", "organization_id": "<org-id>", "scopes": ["jobs:write", "providers:execute"]})).await?;println!("Store this key: {}", key.raw_key);
// List API keyslet keys = client.list_api_keys().await?;
// Revoke an API keyclient.delete_api_key("<key-id>").await?;# Create an API key (raw key shown only once!)curl -X POST $FABRIC_URL/v1/api-keys \ -H 'content-type: application/json' \ -d '{"name":"my-service-key","organization_id":"<org-id>","scopes":["jobs:write","providers:execute"]}'
# List API keyscurl $FABRIC_URL/v1/api-keys
# Revoke an API keycurl -X DELETE $FABRIC_URL/v1/api-keys/<key-id>Events
Section titled “Events”// Stream all eventsawait fabric.streamEvents((event) => { console.log(event.kind, event.payload);});
// Stream job eventsawait fabric.streamEvents("<job-id>", (event) => { console.log(event.kind);});
// Wait for a workflow runconst result = await fabric.waitForRun("<run-id>", { onEvent: (e) => console.log(e.kind),});# Stream all eventsfor event in fabric.stream_events(): print(event["kind"], event.get("payload"))
# Stream job eventsfor event in fabric.stream_job_events("<job-id>"): print(event["kind"])
# Stream workflow run eventsfor event in fabric.stream_run_events("<run-id>"): print(event["kind"])// Stream all eventslet mut stream = client.stream_events().await?;while let Some(event) = stream.next().await { println!("{} {:?}", event.kind, event.payload);}# Stream all events (SSE)curl -N $FABRIC_URL/v1/events/stream
# Stream job eventscurl -N $FABRIC_URL/v1/jobs/<job-id>/events
# Stream workflow run eventscurl -N $FABRIC_URL/v1/workflow-runs/<run-id>/events
# WebSocket eventswscat -c wss://gofabric.dev/v1/events/wsUsage & Audit
Section titled “Usage & Audit”// Organization usage summaryconst usage = await fabric.getOrgUsage("<org-id>");
// Detailed usage recordsconst records = await fabric.getOrgUsageRecords("<org-id>");
// Audit logsconst logs = await fabric.getOrgAuditLogs("<org-id>");# Organization usage summaryusage = fabric.get_org_usage("<org-id>")
# Detailed usage recordsrecords = fabric.get_org_usage_records("<org-id>")
# Audit logslogs = fabric.get_org_audit_logs("<org-id>")// Organization usage summarylet usage = client.get_org_usage("<org-id>").await?;
// Detailed usage recordslet records = client.get_org_usage_records("<org-id>").await?;
// Audit logslet logs = client.get_org_audit_logs("<org-id>").await?;# Organization usage summarycurl $FABRIC_URL/v1/organizations/<org-id>/usage
# Detailed usage recordscurl $FABRIC_URL/v1/organizations/<org-id>/usage/records
# Organization audit logscurl $FABRIC_URL/v1/organizations/<org-id>/audit-logs
# Global audit logscurl $FABRIC_URL/v1/audit-logsGraphQL API
Section titled “GraphQL API”The GraphQL API provides an alternative to REST with client-driven field selection and nested resolution. Enable it with --features graphql. The endpoint is POST /graphql.
Query: List Organizations with Teams
Section titled “Query: List Organizations with Teams”# POST /graphql# Authorization: Bearer fab_xxx# Content-Type: application/json
{ organizations(first: 10) { id name slug teams(first: 5) { id name } }}Query: Current User and Permissions
Section titled “Query: Current User and Permissions”{ me { principalId authenticated } myOrganizations { id name } myPermissions { organizationId role }}Mutation: Create an Organization
Section titled “Mutation: Create an Organization”mutation { createOrganization(name: "Acme Corp", slug: "acme") { id name slug createdAt }}Mutation: Submit a Workflow Run
Section titled “Mutation: Submit a Workflow Run”mutation { submitWorkflowRun( name: "content_pipeline" orgId: "<org-id>" input: { topic: "AI trends", platforms: ["twitter", "linkedin"] } ) { id workflowName status createdAt }}Mutation: Approve a Waiting Workflow
Section titled “Mutation: Approve a Waiting Workflow”mutation { approveWorkflowRun( id: "<run-id>" approved: true reason: "Looks good" )}Query: Get Asset Download URL
Section titled “Query: Get Asset Download URL”{ assetDownloadUrl(id: "<asset-id>", ttlSeconds: 3600) { url assetId expiresAt }}Subscription: Workflow Run Events (WebSocket)
Section titled “Subscription: Workflow Run Events (WebSocket)”Connect to wss://gofabric.dev/graphql/ws using the graphql-transport-ws protocol:
subscription { workflowRunEvents(runId: "<run-id>") { id kind kindRaw payload timestamp }}curl Example
Section titled “curl Example”curl -X POST $FABRIC_URL/graphql \ -H "Authorization: Bearer $FABRIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "{ organizations(first: 5) { id name teams(first: 3) { id name } } }"}'GraphiQL Playground
Section titled “GraphiQL Playground”In development mode, open https://gofabric.dev/graphql in a browser to access the interactive GraphiQL playground. The SDL schema is also available at https://gofabric.dev/graphql/sdl.