Lleverage Docs
WebsiteLegalPlatform
  • Welcome
    • What is Lleverage?
    • Organisations
    • Projects
    • Members
  • Workflows
    • Workflows
      • Variables
      • Testing
      • Logs
      • Publishing
      • Version control
      • Workflow Co-Pilot
    • Actions
      • Controls
      • AI
        • Using the Prompt action
        • Prompt engineering
        • Model configuration
        • Agents
      • Tools
      • Integrations
    • Apps
      • Form app
      • Chat app
    • API Endpoints
    • Templates
  • KNOWLEDGE & DATA SETS
    • Knowledge Bases
  • Connections
    • Models
    • Databases
  • Help, Subscription and Other
    • Subscription Management
    • Release Notes
      • Version 0.1 - 15 July 2024
      • Version 0.2 - 6 August 2024
      • Version 0.3 - 23 September 2024
      • Version 0.4 - 7 October 2024
      • Version 0.5 - 28 October 2024
      • Version 0.6 - 6 December 2024
      • Version 0.7 - 14 January 2025
      • Version 0.8 - 11 February 2025
      • Version 0.9 - 21 March 2025
      • Version 1.0 - 8 April 2025
    • Support
Powered by GitBook
On this page

Was this helpful?

  1. Workflows

API Endpoints

PreviousChat appNextTemplates

Last updated 4 months ago

Was this helpful?

Once your workflow is published, you can call it from within your application. A URL and cURL example are provided for calling the workflow.

Below are examples of how you could make the request from within your code base. If you have protected your workflow trigger with a Lleverage API Token, create one under Settings > API Tokens of the project that your workflow belongs to.

async function callWorkflow(workflowId, inputs) {
  const apiUrl = `https://fo10d.lleverage.run/${workflowId}`;
  const apiKey = "your-api-token";

  const response = await fetch(apiUrl, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${apiKey}`,
    },
    body: JSON.stringify(inputs),
  });

  if (!response.ok) {
    throw new Error(`Workflow call failed: ${response.statusText}`);
  }

  const responseText = await response.text();
  try {
    return JSON.parse(responseText);
  } catch (error) {
    return responseText;
  }
}

// Example usage:
const workflowId = "996c2fwy";
const inputs = {
  subject: "Why Silicon deserves a seventh season.",
  targetAudience: "Boomers",
  specificRequirements: "no spoilers",
};

callWorkflow(workflowId, inputs)
  .then((result) => console.log(result))
  .catch((error) => console.error("Error:", error));
async function callWorkflow(workflowId, inputs, onChunk) {
  const apiUrl = `https://fo10d.lleverage.run/${workflowId}`;
  const apiKey = "your-api-token";

  const response = await fetch(apiUrl, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${apiKey}`,
    },
    body: JSON.stringify(inputs),
  });

  if (!response.ok) {
    throw new Error(`Workflow call failed: ${response.statusText}`);
  }

  const reader = response.body.getReader();
  const decoder = new TextDecoder("utf-8");

  let fullResponse = "";

  while (true) {
    const { done, value } = await reader.read();
    if (done) {
      break;
    }
    const chunk = decoder.decode(value);
    fullResponse += chunk;
    onChunk(chunk);
  }

  try {
    return JSON.parse(fullResponse);
  } catch (error) {
    return fullResponse;
  }
}

// Example usage:
const workflowId = "996c2fwy";
const inputs = {
  subject: "Why Silicon deserves a seventh season.",
  targetAudience: "Boomers",
  specificRequirements: "no spoilers",
};

callWorkflow(workflowId, inputs, (chunk) => {
  console.log("Received chunk:", chunk);
})
  .then((result) => console.log("Final result:", result))
  .catch((error) => console.error("Error:", error));
import urllib.request
import json
import os

def call_workflow(workflow_id, inputs):
    url = f"https://fo10d.lleverage.run/{workflow_id}"
    api_key = "your-api-token"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }
    data = json.dumps(inputs).encode('utf-8')
    
    req = urllib.request.Request(url, data, headers, method="POST")
    
    try:
        with urllib.request.urlopen(req) as response:
            response_text = response.read().decode('utf-8')
            return json.loads(response_text)
    except urllib.error.HTTPError as e:
        raise Exception(f"Workflow call failed: {e.reason}")
    except json.JSONDecodeError:
        return response_text

# Example usage:
workflow_id = "996c2fwy"
inputs = {
    "subject": "Why Silicon deserves a seventh season.",
    "targetAudience": "Boomers",
    "specificRequirements": "No spoilers",
}

try:
    result = call_workflow(workflow_id, inputs)
    print(result)
except Exception as error:
    print("Error:", str(error))

We are working hard on our Node SDK, in the meantime using fetch is a good alternative. Our aim is to launch the SDK in early Q2 of 2025.

A workflow URL and cURL example is displayed after publishing.