> ## Documentation Index
> Fetch the complete documentation index at: https://docs.logic.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# Executing an Agent

> How to execute an agent using the Logic API

## Executing an Agent

Use the `POST /agents/{id}/executions` endpoint to run an agent with input and receive the output.

<Info>
  Want to customize agent executions? You can add optional parameters like: -
  [Dynamic Learning](/api-reference/execution-params/dynamic-learning) — enable
  learning from past executions - [Tenant
  ID](/api-reference/execution-params/tenant-id) — isolate learning per customer

  * [Strict Mode](/api-reference/execution-params/strict-mode) — validate input
    strictly against schema -
    [Versioning](/api-reference/execution-params/version) — execute a specific
    version of an agent -
    [Model Override](/api-reference/execution-params/model-override) — specify a
    custom model and reasoning level
</Info>

### Authorization

To access the Logic API, you will need to provide an authorization token. This token is used to authenticate your requests and ensure that only authorized users can access your agents.

<Info>
  Learn more about authorization and how to set up your API token in the [Authorization section](/api-reference/authorization).
</Info>

## Generic Request Example

To evaluate the agent, make a `POST` request to the endpoint with your `input` as the body.

Calling an agent will differ depending on the input schema of your agent. The following example shows how to make a request to an agent of your choosing. You can see a more specific example below.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST 'https://api.logic.inc/v1/agents/{agent_id}/executions'
      -H "Authorization: Bearer $LOGIC_API_TOKEN"
      -H "Content-Type: application/json" -d '{
        {YOUR INPUT JSON HERE}
      }'
  ```

  ```bash httpie theme={null}
  http -A bearer -a $LOGIC_API_TOKEN POST 'https://api.logic.inc/v1/agents/{agent_id}/executions'
      --raw '{
        {YOUR INPUT JSON HERE}
      }'
  ```

  ```python python theme={null}
  import requests

  LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  headers = {
      "Authorization": f"Bearer {LOGIC_API_TOKEN}",
      "Content-Type": "application/json"
  }

  response = requests.post(
      "https://api.logic.inc/v1/agents/{agent_id}/executions",
      headers=headers,
      json={
        {YOUR INPUT JSON HERE}
      }
  )

  print(response.json())
  ```

  ```ruby ruby theme={null}
  require 'net/http'
  require 'json'

  uri = URI('https://api.logic.inc/v1/agents/{agent_id}/executions')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == 'https'

  LOGIC_API_TOKEN = 'ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  request = Net::HTTP::Post.new(uri)
  request['Authorization'] = "Bearer #{LOGIC_API_TOKEN}"
  request['Content-Type'] = 'application/json'
  request.body = '
      {
        {YOUR INPUT JSON HERE}
      }
  '

  response = http.request(request)
  puts response.body
  ```

  ```javascript javascript theme={null}
  const LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

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

  const data = await response.json();
  console.log(data);
  ```

  ```go go theme={null}
  package main

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

  const (
      LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  )

  func main() {
      jsonStr := `{
        {YOUR INPUT JSON HERE}
      }`

      // Create request
      req, err := http.NewRequest("POST", "https://api.logic.inc/v1/agents/{agent_id}/executions", bytes.NewBufferString(jsonStr))
      if err != nil {
          panic(err)
      }

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

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

      // Read response
      body, err := ioutil.ReadAll(resp.Body)
      if err != nil {
          panic(err)
      }

      fmt.Println(string(body))
  }
  ```

  ```java java theme={null}
  // 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 ApiClient {
      private static final String LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

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


          MediaType JSON = MediaType.get("application/json; charset=utf-8");
          String jsonBody = """
      {
        {YOUR INPUT JSON HERE}
      }
          """;

          RequestBody body = RequestBody.create(jsonBody, JSON);
          Request request = new Request.Builder()
              .url("https://api.logic.inc/v1/agents/{agent_id}/executions")
              .post(body)
              .addHeader("Authorization", "Bearer " + LOGIC_API_TOKEN)

              .addHeader("Content-Type", "application/json")
              .build();

          try (Response response = client.newCall(request).execute()) {
              String responseBody = response.body().string();
              System.out.println(responseBody);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  ```
</CodeGroup>

<Note>
  Replace any **\{id}** in the example code, such as **\{agent\_id}** with the ID you need for your specific API call.
</Note>

<Note>
  Replace `{YOUR INPUT JSON HERE}` with the correct input for your agent. You can find the required fields in your agent’s [Input Schema](/api-reference/agents/input-schemas).
</Note>

## Specific Example Request

Making a request to an agent will differ depending on the input schema of your agent. For this example, the input schema requires a `content` field. This agent is used as a Redact PII API.

You pass in a string, and it will return the string with PII redacted, as well as an array of the redacted entities. The following example shows how to make a request to this agent.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST 'https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions'
      -H "Authorization: Bearer $LOGIC_API_TOKEN"
      -H "Content-Type: application/json" -d '{
        "content": "Steve emailed me at my personal address: mary@yahoo.com."
      }'
  ```

  ```bash httpie theme={null}
  http -A bearer -a $LOGIC_API_TOKEN POST 'https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions'
      --raw '{
        "content": "Steve emailed me at my personal address: mary@yahoo.com."
      }'
  ```

  ```python python theme={null}
  import requests

  LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  headers = {
      "Authorization": f"Bearer {LOGIC_API_TOKEN}",
      "Content-Type": "application/json"
  }

  response = requests.post(
      "https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions",
      headers=headers,
      json={
        "content": "Steve emailed me at my personal address: mary@yahoo.com."
      }
  )

  print(response.json())
  ```

  ```ruby ruby theme={null}
  require 'net/http'
  require 'json'

  uri = URI('https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == 'https'

  LOGIC_API_TOKEN = 'ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  request = Net::HTTP::Post.new(uri)
  request['Authorization'] = "Bearer #{LOGIC_API_TOKEN}"
  request['Content-Type'] = 'application/json'
  request.body = '
      {
        "content": "Steve emailed me at my personal address: mary@yahoo.com."
      }
  '

  response = http.request(request)
  puts response.body
  ```

  ```javascript javascript theme={null}
  const LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

  const response = await fetch(
    "https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${LOGIC_API_TOKEN}`,
        "Content-Type": "application/json",
      },
      body: '{\
        "content": "Steve emailed me at my personal address: mary@yahoo.com."\
      }',
    },
  );

  const data = await response.json();
  console.log(data);
  ```

  ```go go theme={null}
  package main

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

  const (
      LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  )

  func main() {
      jsonStr := `{
        "content": "Steve emailed me at my personal address: mary@yahoo.com."
      }`

      // Create request
      req, err := http.NewRequest("POST", "https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions", bytes.NewBufferString(jsonStr))
      if err != nil {
          panic(err)
      }

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

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

      // Read response
      body, err := ioutil.ReadAll(resp.Body)
      if err != nil {
          panic(err)
      }

      fmt.Println(string(body))
  }
  ```

  ```java java theme={null}
  // 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 ApiClient {
      private static final String LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

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


          MediaType JSON = MediaType.get("application/json; charset=utf-8");
          String jsonBody = """
      {
        "content": "Steve emailed me at my personal address: mary@yahoo.com."
      }
          """;

          RequestBody body = RequestBody.create(jsonBody, JSON);
          Request request = new Request.Builder()
              .url("https://api.logic.inc/v1/agents/d0844039-9f16-40ba-b93e-405f043ef88a/executions")
              .post(body)
              .addHeader("Authorization", "Bearer " + LOGIC_API_TOKEN)

              .addHeader("Content-Type", "application/json")
              .build();

          try (Response response = client.newCall(request).execute()) {
              String responseBody = response.body().string();
              System.out.println(responseBody);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  ```
</CodeGroup>

<Note>
  This agent redacts PII from a block of text. Your agent may expect different input—refer to its input schema for details.
</Note>

### Example Response

```json theme={null}
{
  "redactedText": "{{ name }} emailed me at my personal address: {{ email }}.",
  "redactedEntities": ["Steve", "mary@yahoo.com"]
}
```
