Apps

The Apps API allows you to execute your Scout apps.


POSThttps://api.scoutos.com/v1/apps/execute

Execute an App

This route executes your app and returns the output of each block that was executed.

Required attributes

  • Name
    id
    Type
    string
    Description

    The ID of the app. This can be found on the app page.

  • Name
    inputs
    Type
    object
    Description

    The inputs of the app. These are the value that are defined as the inputs when creating the app.

Optional attributes

  • Name
    streaming
    Type
    boolean
    Description

    A boolean indicating if the response should be sent as Server-sent events.

Response Body

  • Name
    id
    Type
    string
    Description

    The ID of the execution

  • Name
    outputs
    Type
    object
    Description

    The output values of the blocks that were executed. The keys of this object are the block names. They have a .output node which contains the output of the block and a .metadata node which contains metadata about the execution of the block.

Streaming

Overview

Streaming enables client-side applications to receive live updates of your application's output as it executes. By setting the streaming attribute to true, your application will generate Server-Sent Events (SSE) that the client can monitor. Learn more about Server-Sent Events here.

Event Types

Your application can generate the following named events:

  1. Message Event: This event is activated whenever a block in your application produces an output.
    • Usage: For example, in a text generation block, an event is emitted for every generated token. In a collection search block, an event is triggered once the search is complete.
    • Data Format: The event.data attribute contains a JSON object representing the block's output. For a text generation block named 'output', the text can be found at JSON.parse(event.data).output.output.
    • Completion Signal: The event.data will equal "DONE" when the application run is complete, indicating the end of the process.
  2. Start Message Event: This optional event can be set up in the block settings within the dashboard. It is useful for showing a custom message to the user when a block starts execution.
    • Data Content: The event.data attribute will include the start message set for the block.
  3. Error Event: This event is activated if an error occurs during application execution.
    • Error Details: The event.data will contain the error message.

Implementation Example

To handle SSE in your application, you can use libraries like sse.js. Below is a JavaScript example showing how to consume these events:

const { SSE } = require('sse.js')

const source = new SSE('<https://api.scoutos.com/v1/flow/execute>', {
  headers: {
    'Content-Type': 'application/json',
    Authorization: `Bearer SECRET_KEY`,
  },
  payload: JSON.stringify({
    "inputs": {
      "input": "What is scout?"
    }
  }),
})

source.addEventListener('message', function (event) {
  if (event.data === '[DONE]') {
    console.log('Execution complete!')
    return
  }

  const payload = JSON.parse(event.data)
  const blockName = Object.keys(payload)[0]
  const result = payload[blockName].output

  console.log('Block Output:', result)
})

source.addEventListener('start_message', function (event) {
  console.log('Start Message:', event.data)
})

source.addEventListener('error', function (event) {
  console.log('Error:', event.data)
})

Request

POST
https://api.scoutos.com/v1/apps/execute
curl  -X POST \
'https://api.scoutos.com/v1/apps/execute' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer SECRET_KEY' \
--data-raw '{
  "id": <APP_ID>,
  "inputs": {
    "input": "What is scout?",        
  }
}'

Response

{
  "id": "abc-123-foo",
  "outputs": {
    "vector_search": {
      "output": [
        {
          "similarity": 0.9,
          "text": "hello"
        }
      ],
      "metadata": {
        "elapsed_time_ms": 200
      }
    },
    "output": {
      "output": "hello!!",
      "metadata": {
        "elapsed_time_ms": 122
      }
    }
  }
}