Skip to main content
Premium: This endpoint is available only on Pro, Ultra, and Premium plans. See Pricing.

Overview

The Graph Workflow API enables you to create and execute complex multi-agent workflows using a directed graph structure. Agents serve as nodes in the graph, and edges define the flow of data and execution between agents. This allows for sophisticated parallel processing, sequential pipelines, and complex multi-layer workflows. Endpoint: POST /v1/graph-workflow/completions Base URL: https://api.swarms.world (production) or your custom deployment URL

Authentication

All requests require an API key passed in the x-api-key header:

Input Parameters

GraphWorkflowInput Schema

AgentSpec Schema

EdgeSpec Schema

Edge Format Options:
  • Dictionary: {"source": "Agent1", "target": "Agent2", "metadata": {...}}
  • Tuple: ("Agent1", "Agent2") or ("Agent1", "Agent2", {"metadata": {...}})
  • EdgeSpec object: Pydantic EdgeSpec instance

Output Parameters

GraphWorkflowOutput Schema

Usage Schema

Cost Calculation

Graph Workflow uses unified pricing with agent costs. For detailed pricing information, see the Pricing page.

Error Responses

Examples

Example 1: Basic Sequential Workflow

This example demonstrates a simple two-agent sequential workflow where one agent performs research and another analyzes the results.
Expected Output:

Example 2: Parallel Workflow with Multiple Entry Points

This example demonstrates a workflow with multiple parallel entry points that converge into a single analysis agent.
Expected Output:

Example 3: Complex Multi-Layer Workflow

This example demonstrates a sophisticated three-layer workflow with data collection, analysis, validation, and synthesis stages.
Expected Output:

Example 4: Workflow with Edge Metadata

This example demonstrates how to use custom metadata on edges to provide additional context and configuration.
Expected Output:

Example 5: Async Workflow with Vision Support

This example demonstrates an asynchronous workflow request with image input for vision-enabled agents.
Expected Output:

Best Practices

  1. Agent Naming: Use descriptive, unique names for agents as they serve as node identifiers in the graph.
  2. Entry and End Points: Always specify entry_points and end_points to ensure predictable workflow execution.
  3. Edge Definitions: Ensure all edges reference valid agent names. The source and target must match agent_name values.
  4. Timeout Configuration: Set appropriate timeouts based on workflow complexity:
    • Simple workflows: 300 seconds (5 minutes)
    • Medium workflows: 600 seconds (10 minutes)
    • Complex workflows: 900+ seconds (15+ minutes)
  5. Error Handling: Always check response status codes and handle errors appropriately. Use try-except blocks for network errors.
  6. Token Management: Monitor token usage through the usage field in responses to optimize costs and stay within limits.
  7. Model Selection: Choose appropriate models based on task requirements:
    • For vision tasks: Use vision-capable models like gpt-4.1
    • For complex reasoning: Use models like claude-sonnet-4-20250514
    • For cost efficiency: Use gpt-4.1-mini for simpler tasks
  8. Workflow Compilation: Keep auto_compile enabled (default) for optimal performance, unless you need to debug workflow structure.
  9. Parallel Execution: Design workflows with multiple entry points to leverage parallel execution capabilities.
  10. Metadata Usage: Use edge metadata to provide additional context or configuration that can be used by custom workflow logic.

Rate Limits

Rate limits are enforced per API key and subscription tier:
  • Free Tier: 100 requests per minute, 350 requests per hour, 1,200 requests per day
  • Premium Tier: 2,000 requests per minute, 10,000 requests per hour, 100,000 requests per day
Rate limit information is returned in response headers:
  • X-RateLimit-Limit-Minute: Requests allowed per minute
  • X-RateLimit-Remaining-Minute: Requests remaining in the current minute
  • X-RateLimit-Limit-Day: Requests allowed per day
  • X-RateLimit-Remaining-Day: Requests remaining today
  • X-RateLimit-Reset: Unix timestamp when the minute window resets
  • X-RateLimit-Tier: Your current tier (free or premium)

Support

For additional support, examples, and updates:
  • Check the main documentation: Swarms API Documentation
  • Review example code in the examples/multi_agent/graph_workflow/ directory
  • Contact support through your Swarms dashboard