Skip to main content
How do you turn a multi-step LLM workflow into an API endpoint your app can call?

How do you turn a multi-step LLM workflow into an API endpoint your app can call?

Turn a multi-step LLM workflow into an API endpoint with Sim: define inputs, deploy, call the v2 execute endpoint, then compare a FastAPI or LangGraph build.

You turn a multi-step LLM workflow into an API endpoint by putting the steps behind one HTTP route that takes JSON in and returns the final result. This guide is for developers whose app needs to call a chain of model and tool steps as one HTTP request. In Sim, the open-source AI workspace for building and deploying AI agents, you build the steps in the workflow builder, declare the request fields on the Start block, click Deploy, and your app calls POST /api/v2/workflows/{workflow-id}/execute with a Sim API key in the X-API-Key header. Sim gives you synchronous, streaming, and async modes, numbered versions with rollback, and a trace of every run, with no server for you to host on Sim Cloud. If you would rather write it yourself, you wrap the chain in a FastAPI or Express service, or serve a LangGraph graph with LangSmith Agent Server. This guide covers both paths.

TL;DR

  • Build: connect Agent blocks, tools, and logic in the workflow builder. Test with Run.
  • Define the contract: add input fields on Start, such as ticket and customerId. Callers send them inside input.
  • Deploy: open Deploy → General and click Deploy. API calls use this live snapshot, not your draft.
  • Authenticate: create a key in Settings → Sim API keys and send it as X-API-Key.
  • Call: POST https://www.sim.ai/api/v2/workflows/{workflow-id}/execute with {"input": {...}}. Read data.status and data.output.
  • Pick a mode: default sync, stream: true for Server-Sent Events, or async: true for a 202 receipt you poll.
  • Operate: each deploy is a version you can compare, pin with run.version, or promote back to live. Logs shows every run block by block.

What does "turn a workflow into an API endpoint" actually mean?

It means your app sends one request and gets back one result, while the endpoint runs every step in between: classify the input, fetch context, call one or more models, call tools, and shape the answer.

A useful endpoint needs more than a route. It needs:

  1. A stable input contract. Named fields with types, so your app knows what to send.
  2. A predictable output. One result your code can read without guessing.
  3. Authentication. Only your backend can call it.
  4. The right response mode. Wait for the answer, stream tokens to a user, or start a long job and check back.
  5. Versioning. Changing a prompt must not silently break the app that depends on it.
  6. Visibility. When a call fails, you can see which step failed and what it received.

The rest of this guide shows how Sim covers each one, then what it takes to build the same thing in code. If the steps themselves are still a sketch, read what an agentic workflow is first.

How do you build the workflow in Sim?

Take a common example: a support endpoint that receives a ticket, classifies it, and drafts a reply.

  1. Create a workflow. Build it in the workflow builder, or describe it to Sim in Chat and refine the result.
  2. Add an Agent block named Classify. Pass it the ticket with <start.ticket>. Set Response Format to a JSON Schema with category and urgency, so later blocks can read <classify.category> and <classify.urgency> as fields.
  3. Branch if you need to. A Condition block can route urgent tickets differently. Tools and Sim's 280+ integrations can look up the customer's account or search a knowledge base.
  4. Add an Agent block named Draft. Give it the ticket and the classification. Its text answer is <draft.content>.
  5. Optionally end with a Response block. It selects what the run returns, so the API output stays the same shape even if you add steps later.
  6. Test with Run. The editor builds a form from your Start inputs.

The Agent block can call models from OpenAI, Anthropic, Google, xAI, Groq, Cerebras, DeepSeek, Azure, AWS Bedrock, Google Vertex, or OpenRouter, or a local model through Ollama, vLLM, or LiteLLM. Each step can use a different model.

One caution from the Agent docs: when a model returns malformed JSON, the result can fall back to plain text. Validate important fields before a step takes an action, such as sending an email or updating a record.

How do you define the request body your app sends?

The Start block is the API's input contract. (Older workflows may show an API (Legacy) trigger; new workflows use Start.)

Open Start's Inputs and add fields. Each has a name, a type (string, number, boolean, object, array, or files), a description, and an optional default. For the support example:

FieldTypeRead downstream as
ticketstring<start.ticket>
customerIdstring<start.customerId>

Callers put these fields inside the request's input object:

1
{
2
  "input": {
3
    "ticket": "I was charged twice for my November invoice.",
4
    "customerId": "cus_4821"
5
  }
6
}

A supplied value overrides the default. Sim coerces simple values, and an invalid number or boolean can fail the run at input validation. For stricter checks, such as a required non-empty ID, add an early Condition block. The v2 API also rejects unknown top-level fields with a 400, so a typo like inptu fails loudly instead of being ignored.

How do you deploy it?

You need workspace Admin access to deploy.

  1. Open Deploy → General.
  2. Click Deploy for the first version.
  3. Confirm the Live Workflow preview and the new row in the Versions table.

Deploying freezes a snapshot of the workflow. Later edits change the draft, not the live endpoint. When the draft differs from what is live, an Update button appears in the toolbar; click it to deploy the next version.

Tables, files, secrets, and outside services the workflow uses are not frozen by a deploy. A changed knowledge base or credential affects the live endpoint right away.

How do you get an API key?

Create a personal key in Account settings → Sim API keys, a workspace key in Workspace settings → Sim API keys, or a key from Deploy → API → Generate API Key.

  • A personal key acts as you, across the workspaces you can access, with your current role.
  • A workspace key acts as the workspace, for one workspace, and is managed by workspace Admins.

When you create a key, choose its Access (Full access or Read only) and when it Expires (30 days, 90 days, 1 year, or never). A read-only key cannot run workflows, so use full access for an endpoint key. Sim shows the full key once. Store it as a server environment variable such as SIM_API_KEY.

Never ship the key to a browser or mobile client. Your frontend should call your own backend, which checks what the user is allowed to do and then calls Sim.

API-key access is the default. Deploy → API → Edit API Info can switch the endpoint to Public, which lets anyone with the URL run it. Organization policy can turn public access off.

How do you call the endpoint?

The workflow ID is in the workflow builder URL: https://www.sim.ai/workspace/{workspaceId}/w/{workflowId}. For self-hosted Sim, replace https://www.sim.ai with your deployment's origin.

1
curl --fail-with-body -X POST \
2
  "https://www.sim.ai/api/v2/workflows/$WORKFLOW_ID/execute" \
3
  -H "X-API-Key: $SIM_API_KEY" \
4
  -H 'Content-Type: application/json' \
5
  -d '{"input": {"ticket": "I was charged twice for my November invoice.", "customerId": "cus_4821"}}'

A synchronous call waits for the run to finish and returns a run resource inside data:

1
{
2
  "data": {
3
    "runId": "c7a92e15-3f4b-4d8c-a1e6-9b0d5f2c8e74",
4
    "workflowId": "{workflowId}",
5
    "status": "completed",
6
    "output": { "result": "..." },
7
    "blockOutputs": null,
8
    "error": null,
9
    "startedAt": "2026-10-13T12:00:00.000Z",
10
    "endedAt": "2026-10-13T12:00:00.842Z",
11
    "durationMs": 842
12
  }
13
}

Three rules keep your client correct:

  • Check data.status, not just the HTTP code. A workflow that ran and failed can return HTTP 200 with status: "failed" and details in data.error. A run that hits its time limit also comes back as failed.
  • HTTP errors mean the request was rejected. They use an error object with code, message, and a requestId that matches the x-request-id header. 401 is a bad key, 402 a usage limit, 403 a permission problem, 429 a rate limit (honor Retry-After).
  • The envelope is fixed. A Response block chooses what goes in data.output. It does not change the v2 status code, headers, or envelope.

To get one step's output as well as the final result, add selectedOutputs, such as ["classify.category"]. Selected values come back in data.blockOutputs, keyed by the selector you sent. Selectors use the block name lowercased, with spaces and dots removed, followed by the field path.

The Deploy → API tab generates cURL, Python, JavaScript, and TypeScript versions of this call for your workflow.

Should the call be synchronous, streaming, or async?

Pick the mode by who is waiting for the answer.

ModeRequestYou getUse it when
SynchronousdefaultThe full run resource in one JSON responseA backend needs the result before it continues
Streaming"stream": true plus selectedOutputsServer-Sent Events (a long-lived HTTP response that sends events as they happen)A person is watching the answer appear
Async"async": trueHTTP 202 with runId and statusUrlThe run may take minutes, or the caller should not wait

Streaming. Choose the fields to stream, usually an Agent's content. Add the X-Sim-Stream-Protocol: agent-events-v1 header for live answer tokens. Without it, the answer text arrives after the model's final turn settles. You can also add includeThinking and includeToolCalls to stream reasoning and tool events.

1
curl -N -X POST "https://www.sim.ai/api/v2/workflows/$WORKFLOW_ID/execute" \
2
  -H "X-API-Key: $SIM_API_KEY" \
3
  -H 'Content-Type: application/json' \
4
  -H 'X-Sim-Stream-Protocol: agent-events-v1' \
5
  -d '{"input": {"ticket": "I was charged twice."}, "stream": true, "selectedOutputs": ["draft.content"]}'

Async. Send "async": true, store the runId, and poll the status URL with a delay:

1
curl --fail-with-body \
2
  "https://www.sim.ai/api/v2/workflows/$WORKFLOW_ID/runs/$RUN_ID?includeOutput=true" \
3
  -H "X-API-Key: $SIM_API_KEY"

Stop polling on completed, failed, or cancelled. A paused run is waiting, for example on a Human approval step. Async needs a full-access API key or an OAuth token with api:write and always uses the deployed version. It cannot be combined with streaming or selectedOutputs. An optional executionTimeoutSeconds can shorten your plan's time limit but never extend it.

A middle ground. waitTimeoutSeconds makes a synchronous call wait up to that many seconds. If the run is still going, it keeps running in the background and you get the same 202 receipt as async. It cannot be combined with async or stream, and it needs a full-access API key or an OAuth token with api:write.

Safe retries. With an API key or OAuth token, send your own X-Run-Id to name the run; anonymous calls to a public endpoint can't set it. Reusing the ID returns 409 instead of starting a duplicate. After a lost response, check that run ID before trying again, and don't start a new run just because the check comes back empty: a missing record doesn't prove no work started.

Time limits. On Sim Cloud, a synchronous run can take up to 5 minutes on Community and 50 minutes on Pro, Max, Team, and Enterprise. Async runs can take up to 90 minutes, and Enterprise can configure up to 7 days. See how long a run can take for the current table.

How do you change the workflow without breaking your app?

Every deploy records a numbered version, who deployed it, and when. From a version's ⋮ menu you can Rename, add a description, Compare versions, Promote to live, or Load deployment into your draft.

  • Change safely: edit the draft, test with Run, then click Update. Live callers keep the old version until then.
  • Roll back: Promote to live on an earlier version. It reuses that snapshot and does not touch your draft.
  • Pin a version: an app can send "run": {"source": "deployment", "version": 3} to run version 3 even after you deploy version 4. This needs workspace Write access with an API key or OAuth token.
  • Test the draft from code: "run": {"source": "draft"} runs the saved draft for a personal key or OAuth caller with Write access. It supports sync and streaming, not async.

Keep field names stable between versions. If you must rename an input, add the new field first, move callers over, then remove the old one.

How do you debug a call that went wrong?

Open Logs. Every run your app starts appears with its execution ID, an API trigger, status, duration, and cost.

Select a run to open Log Details. Trace shows timed spans for each block, nested workflow, model request, and tool call. Each span shows the input it received after references resolved, and the output or error it produced. That is usually enough to find the step that got an empty field or a malformed value. Protected secret values are masked in logs.

For production monitoring beyond one run, see AI agent observability.

How do you build the same endpoint in code?

The code path is a web service you write and run. A minimal FastAPI version of the support example looks like this:

1
import os
2
import secrets
3
 
4
from fastapi import FastAPI, HTTPException, Header
5
from pydantic import BaseModel
6
 
7
app = FastAPI()
8
 
9
class TicketIn(BaseModel):
10
    ticket: str
11
    customer_id: str
12
 
13
async def call_model(prompt: str) -> str:
14
    """Call your LLM provider's SDK here."""
15
    raise NotImplementedError
16
 
17
@app.post("/triage")
18
async def triage(body: TicketIn, x_api_key: str | None = Header(default=None)):
19
    if x_api_key is None or not secrets.compare_digest(x_api_key, os.environ["SERVICE_KEY"]):
20
        raise HTTPException(status_code=401)
21
    category = await call_model(f"Classify this ticket: {body.ticket}")
22
    reply = await call_model(f"Draft a reply for a {category} ticket: {body.ticket}")
23
    return {"category": category, "reply": reply}

That is the easy part. To match what a deployed endpoint needs, you also build:

  • Streaming. A StreamingResponse or Server-Sent Events route, plus a client that handles partial output and errors mid-stream.
  • Long runs. FastAPI's own docs note that BackgroundTasks run in the same process and point to tools like Celery, with a queue such as Redis or RabbitMQ, for heavy work. That means a worker, a job table, and a status route.
  • Versioning. Prompts and chain code ship with your service, so a prompt change is a code deploy. Pinning callers to an old version means running two versions side by side.
  • Visibility. Tracing every model and tool call needs an observability tool wired into the chain.
  • Keys and retries. Key storage, rotation, rate limits, and duplicate protection.

LangGraph. If your chain is a LangGraph graph, LangSmith Agent Server can serve it as an API. You describe the app in a langgraph.json file, run langgraph dev locally (the API listens on port 2024 by default), and call routes such as POST /runs/wait for a result or POST /runs/stream for streaming. Agent Server adds threads, persistence, and a task queue. langgraph up runs a production-like local stack in Docker with PostgreSQL and Redis, and you choose where it runs in production: LangSmith Cloud, a hybrid setup, or your own infrastructure. You still write and version the graph in code. Assistants add versioned configuration on top: editing an assistant creates a new version you can promote or roll back, and prompts or models can change without redeploying the graph. See LangChain vs LangGraph for how the two relate.

Which approach should you choose?

SimFastAPI or Express wrapperLangGraph with Agent Server
How you build the stepsVisually, in Chat, or with codeCodeCode (a graph)
EndpointPOST /api/v2/workflows/{id}/execute, created on deployRoutes you writeRoutes the server provides
AuthSim API keys or OAuth; optional public accessYou build itServer and deployment options
Streamingstream: true with Server-Sent EventsYou build itBuilt in
Long runsasync: true and a runs resourceYou add a queue and workersBuilt-in task queue
Versions and rollbackNumbered deploys, pin with run.version, promote to liveYour release processAssistant versions you can promote or roll back; graph code ships through your release process
Run tracesLogs with per-block tracesYou add tracingLangSmith
HostingSim Cloud or self-hosted SimYou host itLangSmith Cloud, hybrid, or self-hosted
Who can change promptsMembers with Write access edit the draft; Admins deploy itEngineersEngineers for graph code; assistant config (prompts, models) can change without a code deploy

Write it yourself when the chain is a few lines, your team already runs Python or Node services with auth and monitoring, and only engineers will change it.

Use LangGraph when you want graph-shaped agent code with threads and persistence, and your team is comfortable owning the code and its deployment.

Use Sim when the workflow will change often, calls many tools, or is owned by people outside engineering, and you want versions, streaming, async runs, and traces without building them. Your app still just makes one HTTP call. For a broader view of this choice, see visual AI agent builder vs code-first framework.

What should you check before your app depends on the endpoint?

  • Inputs are named, typed, and documented on Start.
  • The output has one stable shape, ideally set by a Response block.
  • The workflow is deployed, and the live version is the one you tested.
  • The API key is full access, stored on your server, and has an owner and an expiry plan.
  • Your client checks data.status and handles failed and paused.
  • Retries honor Retry-After and use X-Run-Id to avoid duplicate runs.
  • Long runs use async: true or waitTimeoutSeconds instead of a long client timeout.
  • Anyone changing the workflow knows edits go live only on Update.
  • You have opened a real run in Logs and read its trace.

Other ways to expose the same workflow: turn it into an MCP tool, which AI assistants can discover and call through the Model Context Protocol (an open standard for connecting AI apps to tools), or deploy it as a chat. For the full request reference, see Sim's API deployment docs, API getting started, and authentication. To get started, open Sim, build the workflow, and deploy it.

FAQ

How do I turn a multi-step LLM workflow into an API endpoint?

In Sim, build the steps in the workflow builder, declare the request fields on the Start block, deploy from Deploy → General, create a Sim API key, and call POST /api/v2/workflows/{workflow-id}/execute with the key in the X-API-Key header and your fields inside an input object. In code, you write a web service such as FastAPI or Express around the chain, or serve a LangGraph graph with LangSmith Agent Server, and you own hosting, auth, retries, and logs.

What is the Sim endpoint for running a workflow?

The current endpoint is POST /api/v2/workflows/{workflow-id}/execute on https://www.sim.ai for Sim Cloud, or on your own origin for self-hosted Sim. The older v1 execute route is legacy; new integrations should use v2.

Which header does the Sim API use for authentication?

Send a Sim API key in the X-API-Key header. The v2 API accepts Authorization: Bearer only for OAuth access tokens, not for API keys.

What does the Sim API return?

A synchronous call returns a run resource inside data, with runId, workflowId, status, output, blockOutputs, error, and timing fields. A workflow that ran and failed can still return HTTP 200 with status set to failed, so always check data.status.

Can a Sim workflow API stream LLM output?

Yes. Set stream to true and choose fields with selectedOutputs, such as agent.content, to receive Server-Sent Events. Add the X-Sim-Stream-Protocol: agent-events-v1 header for live answer tokens, and includeThinking or includeToolCalls for reasoning and tool events.

How do I run a long LLM workflow without holding the HTTP connection open?

Send async set to true. Sim answers with HTTP 202, a runId, and a statusUrl. Poll GET /api/v2/workflows/{workflow-id}/runs/{runId}?includeOutput=true until status is completed, failed, or cancelled.

Do edits to my workflow change the live API right away?

No. Each deployment is a numbered snapshot. Edits change the draft only, and API callers keep using the live version until you click Update. You can promote an earlier version to live to roll back.

Can I call a specific version of a deployed workflow?

Yes. Send run with source set to deployment and a version number. The caller needs workspace Write access with an API key or OAuth token, and the workflow must still be deployed.

Can I make a Sim workflow endpoint public?

Yes. In Deploy → API → Edit API Info you can choose Public instead of API Key access. Anyone with the URL can then run the deployed workflow, so limit what its input can do and what its output reveals. Organization policy can turn public access off.

Should I call the Sim API from the browser?

No. Keep the API key on your server. Have your browser app call your own backend, check what the user may do, and send the Sim request from there.

When is a hand-written API better than Sim?

Write it yourself when the chain is a few lines of code, your team already runs Python or Node services with auth and monitoring, and nobody outside engineering needs to change prompts or steps. Choose Sim when the workflow will change often, touches many tools, or needs versioning, logs, and streaming without building them.

Can I see what happened inside a run my app started?

Yes. Every API run is recorded in Logs with its trigger, status, duration, and cost. The Trace view shows timed spans for each block, model request, and tool call, with resolved inputs and outputs.

Every agent your company runs. All in one place.