Skip to main content

Async Execution

By default, an agent execution runs synchronously: the request blocks until the agent finishes and the response contains the output. For long-running agents, you can instead run the execution asynchronously by adding the execMode query parameter. The execMode parameter accepts two values:
  • sync (default) — the request waits for the agent to finish and returns the output.
  • async — the request returns immediately with an execution record you can poll.
Async execution is useful for long-running or agentic agents, and for starting many executions in parallel without holding open a request for each one.

Step 1: Start the execution

Add ?execMode=async to your execution request. Instead of the agent output, you receive an execution object with an id and a status of IN_PROGRESS.
curl -X POST 'https://api.logic.inc/v1/agents/{agent_id}/executions?execMode=async'
  -H "Authorization: Bearer $LOGIC_API_TOKEN"
  -H "Content-Type: application/json"
  -d '{
        {YOUR INPUT JSON HERE}
      }'
http POST 'https://api.logic.inc/v1/agents/{agent_id}/executions'
  execMode==async
  "Authorization:Bearer $LOGIC_API_TOKEN"
  "Content-Type:application/json"
  --raw '{
    {YOUR INPUT JSON HERE}
  }'
import requests

LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

response = requests.post(
    "https://api.logic.inc/v1/agents/{agent_id}/executions",
    params={"execMode": "async"},
    headers={
        "Authorization": f"Bearer {LOGIC_API_TOKEN}",
        "Content-Type": "application/json",
    },
    json={
        # Add your agent input here
    },
)

print(response.status_code, response.text)
require 'net/http'
require 'json'

uri = URI('https://api.logic.inc/v1/agents/{agent_id}/executions')
uri.query = URI.encode_www_form({ execMode: "async" })

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

LOGIC_API_TOKEN = 'ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
headers = {
  "Authorization" => "Bearer #{LOGIC_API_TOKEN}",
  "Content-Type" => "application/json"
}
body = { }.to_json

request = Net::HTTP::Post.new(uri, headers)
request.body = body

response = http.request(request)
puts response.code
puts response.body
const LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const url = new URL("https://api.logic.inc/v1/agents/{agent_id}/executions");
url.searchParams.set("execMode", "async");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${LOGIC_API_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    // Add your agent input here
  }),
});

console.log(await response.json());
package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "net/http"
)

const (
    LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)

func main() {
    url := "https://api.logic.inc/v1/agents/{agent_id}/executions?execMode=async"

    jsonStr := `{
      {YOUR INPUT JSON HERE}
    }`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonStr))
    if err != nil {
        panic(err)
    }

    req.Header.Set("Authorization", "Bearer "+LOGIC_API_TOKEN)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}
// Java requires the OkHttp library. You can add it to your project using Maven or Gradle. Learn more in the Java Quick Start section of the API reference.

import okhttp3.*;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        String json = "{ /* your input JSON here */ }";
        RequestBody body = RequestBody.create(json, MediaType.get("application/json"));

        HttpUrl url = HttpUrl.parse("https://api.logic.inc/v1/agents/{agent_id}/executions")
            .newBuilder()
            .addQueryParameter("execMode", "async")
            .build();

        Request request = new Request.Builder()
            .url(url)
            .addHeader("Authorization", "Bearer ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
            .addHeader("Content-Type", "application/json")
            .post(body)
            .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

Example Response

{
  "id": "ddd36570-bbdc-4ad1-a8d1-58a9de7c8979",
  "documentId": "0b9ff0a0-aafb-45f5-9b63-67985320fe79",
  "status": "IN_PROGRESS",
  "input": {
    "artistName": "Adele"
  },
  "output": null,
  "error": null,
  "cached": false,
  "source": "API"
}
If caching is enabled (useCache=true) and a matching prior execution exists, an async request returns the cached result right away with status already SUCCESS and "cached": true, rather than IN_PROGRESS.

Step 2: Poll for the result

Use the execution id from the response to poll the GET /agent_executions/{id} endpoint. Keep polling until status is SUCCESS or ERROR. When the execution succeeds, the output field contains the agent’s result.
curl
curl 'https://api.logic.inc/v1/agent_executions/{execution_id}'
  -H "Authorization: Bearer $LOGIC_API_TOKEN"
A status of IN_PROGRESS means the agent is still running—wait and poll again. SUCCESS means output is populated; ERROR means the error field explains what went wrong.