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

# Invoke no-code agents via the API

> Turn deployed no-code agents into microservices with the Applications API. Use text generation and research agents as tools in your applications.

<Info>No-code applications are now called [no-code agents](/no-code/introduction). The [Applications API](api-reference/application-api/applications), which you can use to programmatically interact with no-code agents, still uses the term `application` to minimize breaking changes.</Info>

The Applications API allows you to turn deployed [no-code agents](/no-code/introduction) into microservices, which can also be used as tools in [tool calling](/home/applications-tool-calling). Business users can define inputs, prompts, and outputs, and developers can then add them to other applications, UIs, or services.

This guide shows how to use the `/applications` endpoint to generate content from no-code agents.

If you do not have a deployed no-code agent, follow the guides to build an agent with [text generation](/no-code/text-generation) or [research](/no-code/research) capabilities in AI Studio.

<Warning>
  The `/applications` endpoint supports only agents with [text generation](/no-code/text-generation) and [research](/no-code/research) capabilities. It does not support [chat](/no-code/chat) agents.
</Warning>

<Note>
  You need an API key to access the Writer API. Get an API key by following the steps in the [API quickstart](/home/quickstart).

  We recommend setting the API key as an environment variable in a `.env` file with the name `WRITER_API_KEY`.
</Note>

## Endpoint overview

**URL:** `POST https://api.writer.com/v1/applications/{application_id}`

<Warning>
  Using the `/applications` endpoint incurs charges for **model usage**. See the [pricing page](/home/pricing) for more information.
</Warning>

<CodeGroup>
  ```bash cURL theme={null}
  curl 'https://api.writer.com/v1/applications/<application-id>' \
  -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $WRITER_API_KEY" \
  --data-raw '{
    "inputs": [
      {
        "id": "Product description",
        "value": [
          "Terra running shoe"
        ]
      }
    ]
  }'
  ```

  ```python Python theme={null}
  from writerai import Writer

  # Initialize the client. If you don't pass the `api_key` parameter,
  # the client looks for the `WRITER_API_KEY` environment variable.
  client = Writer()

  response = client.applications.generate_content(
      application_id="<application-id>",
      inputs=[
          {
              "id": "Product description",
              "value": ["Terra running shoe"]
          }
      ]
  )

  print(response.suggestion)
  ```

  ```javascript JavaScript theme={null}
  import { Writer } from 'writer-sdk';

  // Initialize the client. If you don't pass the `apiKey` parameter,
  // the client looks for the `WRITER_API_KEY` environment variable.
  const client = new Writer();

  const response = await client.applications.generateContent(
      "<application-id>",
      {
          inputs: [
              {
                  id: "Product description",
                  value: ["Terra running shoe"]
              }
          ]
      }
  );

  console.log(response.suggestion);
  ```
</CodeGroup>

### Path parameters

| Parameter        | Type   | Description                                                                                                                                                                                                                                                                                                                                              |
| ---------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `application_id` | string | The ID of the deployed agent. You can find this in the URL of the agent in AI Studio: `https://app.writer.com/aistudio/organization/<organization-id>/applications/<application-id>`. You can also use the [List applications](/api-reference/application-api/list-applications) endpoint to get the list of deployed agents and see the application ID. |

### Request body

Below are the required and commonly used optional parameters for the `/applications` endpoint.

| Parameter        | Type           | Description                                                                                                                                                                                                                                                                                        |
| ---------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `inputs`         | array          | Input values matching the agent's defined input fields. The input structure depends on the agent capabilities.                                                                                                                                                                                     |
| `inputs[].id`    | string         | The name of the input field. For research, the input id is always `query`.                                                                                                                                                                                                                         |
| `inputs[].value` | array\[string] | An array containing values of the input field. You can pass multiple values for a single input field. If the input field is a file, the value should be the `file_id` from an uploaded file, such as `["1234-abcd-1234"]`. Learn more about how to upload files with the [Files API](/home/files). |

```json theme={null}
{
  "inputs": [
    {
      "id": "string",
      "value": ["string"]
    }
  ]
}
```

See the [applications endpoint reference](/api-reference/application-api/applications) for more information on the request body and the additional parameters you can use to control the agent.

### Response format

The response format depends on the agent capabilities and whether you set the `stream` parameter to `true` or `false`. Only agents with research support streaming responses at this time.

#### Non-streaming response

If you set the `stream` parameter to `false`, the response is delivered as a JSON object with the following parameters:

| Parameter    | Type   | Description                                                  |
| ------------ | ------ | ------------------------------------------------------------ |
| `title`      | string | The name of the output field, as defined in the application. |
| `suggestion` | string | The output of the application call.                          |

```json theme={null}
{
  "title": null,
  "suggestion": "The Terra running shoe combines lightweight materials with advanced cushioning technology to deliver exceptional comfort and performance for every stride."
}
```

#### Streaming response

If you set the `stream` parameter to `true`, the response is delivered as [server-sent events](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events). The event contains several parameters.

The content of the chunk is in the `delta` field. You can also use the `stages` field to get the stages of the research assistant application call, such as "Planning the research" or "Researching and organizing findings."

Below are the important parameters for extracting the output of the application call.

| Parameter              | Type   | Description                                           |
| ---------------------- | ------ | ----------------------------------------------------- |
| `delta`                | object | The content of the chunk.                             |
| `delta.content`        | string | The output of the application call.                   |
| `delta.stages`         | array  | The stage of the research assistant application call. |
| `delta.stages.content` | string | The content of the stage.                             |

```json theme={null}
data: {'delta': {'title': None,
  'content': None,
  'stages': [{'id': 'a5d81590-0120-4404-948b-8075e3610f51',
    'content': 'Initiating a research assistant: 🚗 Automotive assistant',
    'sources': None}]}}
```

## Example: Text generation

Agents used for [text generation](/no-code/text-generation) generate content based on the inputs provided to a specific no-code agent created in AI Studio. This is a great way to enable business users to control prompts and outputs while still allowing developers to add them to other applications, UIs, or services.

To invoke text generation, you need to provide the application ID and the required inputs to the agent. Inputs are defined in the agent within AI Studio.

### Get the text generation inputs

To see the required inputs for the agent, you can view the agent in [AI Studio](https://app.writer.com/aistudio), or you can use the [Get application](/api-reference/application-api/application-details) endpoint to get the agent details, including the inputs.

The example below shows how to use the `Get application` endpoint to get the list of required inputs with their name and types.

<CodeGroup>
  ```bash cURL theme={null}
  curl --location --request GET 'https://api.writer.com/v1/applications/<application-id>' \
   --header "Authorization: Bearer $WRITER_API_KEY"
  ```

  ```python Python theme={null}
  from writerai import Writer

  # Initialize the client. If you don't pass the `api_key` parameter,
  # the client looks for the `WRITER_API_KEY` environment variable.
  client = Writer()

  application = client.applications.retrieve(
      "<application-id>",
  )

  for input_ in application.inputs:
    print(f"{input_.name}: {input_.input_type}")
  ```

  ```javascript JavaScript theme={null}
  import { Writer } from 'writer-sdk';

  // Initialize the client. If you don't pass the `apiKey` parameter,
  // the client looks for the `WRITER_API_KEY` environment variable.
  const client = new Writer();

  const application = await client.applications.retrieve("<application-id>");

  for (const input of application.inputs) {
    console.log(`${input.name}: ${input.input_type}`);
  }
  ```
</CodeGroup>

### Format the request body with the application inputs

The `inputs` parameter is an array of objects, each containing an `id` and `value` field. The `id` field is the name of the input field, and the `value` field is the value of the input field.

```json theme={null}
{
  "inputs": [
    {
      "id": "Text input name",
      "value": ["Input value 1"]
    },
    {
      "id": "File input name",
      "value": ["1234-fileid-1234"]
    }
  ]
}
```

If the input field is a file, the value should be the `file_id` from an [uploaded file](/api-reference/file-api/upload-files).

Your request body should be formatted as a JSON object with values for each input.

### Generate content from the agent

Once you've formatted the request body with the agent inputs, you can invoke the agent using the [Generate content](/api-reference/application-api/applications) endpoint.

The examples below demonstrate calling an agent with text generation capabilities. The agent takes two text inputs: `Product description` and `Target audience`.

<CodeGroup>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.writer.com/v1/applications/<application-id>' \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --data-raw '{
    "inputs": [
      {
        "id": "Product description",
        "value": ["Terra running shoe"]
      },
      {
        "id": "Target audience",
        "value": ["Runners"]
      }
    ]
  }'
  ```

  ```python Python theme={null}
  from writerai import Writer

  # Initialize the client. If you don't pass the `api_key` parameter,
  # the client looks for the `WRITER_API_KEY` environment variable.
  client = Writer()

  response = client.applications.generate_content(
      application_id="<application-id>",
      inputs=[
          {
              "id": "Product description",
              "value": ["Terra running shoe"]
          },
          {
              "id": "Target audience",
              "value": ["Runners"]
          }
      ]
  )

  print(response.suggestion)
  ```

  ```javascript JavaScript theme={null}
  import { Writer } from 'writer-sdk';

  // Initialize the client. If you don't pass the `apiKey` parameter,
  // the client looks for the `WRITER_API_KEY` environment variable.
  const client = new Writer();

  const response = await client.applications.generateContent(
      "<application-id>", 
      {
          inputs: [
              {
                  id: "Product description",
                  value: ["Terra running shoe"]
              },
              {
                  id: "Target audience",
                  value: ["Runners"]
              }
          ]
      }
  );

  console.log(response.suggestion);
  ```
</CodeGroup>

## Example: Research assistant

Agents with [research](/no-code/research) capabilities output a final report after performing research in stages. Because of this, they support streaming responses.

These agents take an array of inputs that contain a single item, formatted as a JSON object with `id` and `value` parameters. It also takes a `stream` parameter that is set to `false` by default.

| Parameter        | Type           | Description                                                                                       |
| ---------------- | -------------- | ------------------------------------------------------------------------------------------------- |
| `inputs`         | array          | An array of objects, each containing an `id` and `value` field.                                   |
| `inputs[].id`    | string         | The name of the input field. For research assistant applications, the input id is always `query`. |
| `inputs[].value` | array\[string] | An array containing the research query.                                                           |
| `stream`         | Boolean        | Whether to stream the response. Defaults to `false`.                                              |

The examples below demonstrate calling an agent to research hotels in San Francisco. The application streams the output as it is generated.

<CodeGroup>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.writer.com/v1/applications/<research-application-id>' \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --data-raw '{
    "inputs": [
      {
        "id": "query", 
        "value": ["Provide a list of three hotels in San Francisco near Union Square within the price range of $100 to $200 per night"]
      }
    ],
    "stream": true
  }'
  ```

  ```python Python theme={null}
  from writerai import Writer

  # Initialize the client. If you don't pass the `api_key` parameter,
  # the client looks for the `WRITER_API_KEY` environment variable.
  client = Writer()

  response = client.applications.generate_content(
      application_id="<research-application-id>",
      inputs=[
          {
              "id": "query",
              "value": ["Provide a list of three hotels in San Francisco near Union Square within the price range of $100 to $200 per night"]
          }
      ],
      stream=True
  )

  for chunk in response:
      if chunk.delta.content:
          print(chunk.delta.content, end="", flush=True)
      elif chunk.delta.stages:
          print(chunk.delta.stages[0].content)
  ```

  ```javascript JavaScript theme={null}
  import { Writer } from 'writer-sdk';

  // Initialize the client. If you don't pass the `apiKey` parameter,
  // the client looks for the `WRITER_API_KEY` environment variable.
  const client = new Writer();

  const response = await client.applications.generateContent(
      "<research-application-id>",
      { 
          inputs: [
              {
                  id: "query",
                  value: ["Provide a list of three hotels in San Francisco near Union Square within the price range of $100 to $200 per night"]
              }
          ],
          stream: true
      } 
  );

  for await (const chunk of response) {
      if (chunk.delta.content) {
          process.stdout.write(chunk.delta.content);
      } else if (chunk.delta.stages) {
          console.log(chunk.delta.stages[0].content);
      }
  }
  ```
</CodeGroup>

## Next steps

Now that you've invoked a no-code agent via the API, learn other ways you can use no-code agents via the API:

* [Run no-code agents asynchronously](/home/async-applications)
* [Use no-code agents in tool calling](/home/applications-tool-calling)
