Skip to content

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" });
const health = await fabric.healthCheck();
const providers = await fabric.listProviders();
// Get current principal
const me = await fabric.getMe();
// List my organizations
const orgs = await fabric.getMyOrganizations();
// List my teams
const teams = await fabric.getMyTeams();
// Get my effective permissions
const perms = await fabric.getMyPermissions();
// Create an organization
const org = await fabric.createOrganization({
slug: "acme", name: "Acme Corp",
});
// Get organization details
const orgDetails = await fabric.getOrganization("<org-id>");
// List organization teams
const teams = await fabric.listTeams("<org-id>");
// List organization members
const members = await fabric.listMembers("<org-id>");
// Create a team
const team = await fabric.createTeam({
organizationId: "<org-id>",
slug: "engineering",
name: "Engineering",
});
// Create an invitation
const invite = await fabric.createInvitation({
organizationId: "<org-id>",
email: "user@example.com",
role: "member",
});
// Single permission check
const allowed = await fabric.checkPermission({
resource: `organization:${orgId}`,
action: "invite",
});
// Batch permission check
const results = await fabric.checkPermissions([
{ resource: `organization:${orgId}`, action: "read" },
{ resource: `team:${teamId}`, action: "create" },
]);
// Submit a job
const job = await fabric.createJob({
modality: "image",
tier: "premium",
input: { prompt: "a cat in space" },
params: { size: "1024x1024" },
organizationId: "<org-id>",
});
// Submit with idempotency key
const job2 = await fabric.createJob({
modality: "text",
input: { prompt: "Hello world" },
organizationId: "<org-id>",
idempotencyKey: "unique-request-id-123",
});
// Get job status
const status = await fabric.getJob("<job-id>");
// List jobs
const jobs = await fabric.listJobs();
// Get job usage
const usage = await fabric.getJobUsage("<job-id>");
import { WorkflowBuilder } from "@fabric-platform/sdk";
// Create a workflow definition
const 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 run
const 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 execution
await fabric.startRun(runId);
// Cancel if needed
await fabric.cancelRun(runId);
// Face swap — swap a persona onto a source image
const 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 video
const 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 URL
const run = await fabric.workflows.runs.submitAndWait("video/face-swap", {
input: {
source_url: "https://example.com/trending-video-frame.jpg",
persona_gallery_id: "gallery-uuid",
},
});
// List available providers
const providers = await fabric.listProviders();
// Execute a provider request
const result = await fabric.executeProvider({
modality: "text",
model: "qwen3:latest",
input: { prompt: "Explain quantum computing in one sentence" },
params: { temperature: 0.7 },
});
// Estimate cost
const estimate = await fabric.estimateCost({
modality: "text",
model: "gpt-4",
input: { prompt: "Hello world" },
});
// Create an API key
const 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 keys
const keys = await fabric.listApiKeys();
// Revoke an API key
await fabric.deleteApiKey("<key-id>");
// Stream all events
await fabric.streamEvents((event) => {
console.log(event.kind, event.payload);
});
// Stream job events
await fabric.streamEvents("<job-id>", (event) => {
console.log(event.kind);
});
// Wait for a workflow run
const result = await fabric.waitForRun("<run-id>", {
onEvent: (e) => console.log(e.kind),
});
// Organization usage summary
const usage = await fabric.getOrgUsage("<org-id>");
// Detailed usage records
const records = await fabric.getOrgUsageRecords("<org-id>");
// Audit logs
const logs = await fabric.getOrgAuditLogs("<org-id>");

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.

# POST /graphql
# Authorization: Bearer fab_xxx
# Content-Type: application/json
{
organizations(first: 10) {
id
name
slug
teams(first: 5) {
id
name
}
}
}
{
me {
principalId
authenticated
}
myOrganizations {
id
name
}
myPermissions {
organizationId
role
}
}
mutation {
createOrganization(name: "Acme Corp", slug: "acme") {
id
name
slug
createdAt
}
}
mutation {
submitWorkflowRun(
name: "content_pipeline"
orgId: "<org-id>"
input: { topic: "AI trends", platforms: ["twitter", "linkedin"] }
) {
id
workflowName
status
createdAt
}
}
mutation {
approveWorkflowRun(
id: "<run-id>"
approved: true
reason: "Looks good"
)
}
{
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
}
}
Terminal window
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 } } }"}'

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.