NAV
shell python

Introduction

ScriptRun Al: Visual Al script builder

Create simple and complex Al scripts to integrate into your business project. Fast, reliable and without limitations.

What is a Project? A project is a container where you can organize and manage your Al scenarios and related data. You can manage access and collaboration by doing projects with your colleagues.

A Script in ScriptRun Al is a sequence of instructions for interacting with language models (such as OpenAl's GPT-4, o1-preview) and third-party services (such as for SEO keyword research) that you specify when you create a Script. Each Scenario consists of a given sequence of Messages, which are text requests to the language models via ARL.

The Scenario API allows you to create, manage, and execute predefined workflows, called Scenarios (scripts), and track their execution through ScenarioRuns. A Scenario is essentially a blueprint that defines a sequence of actions, messages, and conditions, guiding the flow of a conversation, process, or automation task. Scenarios are highly customizable and can be used for a wide range of applications, from chatbot dialogues to complex automation workflows. When you execute a Scenario, the system generates a ScenarioRun. This is an instance of the Scenario's execution, which tracks real-time interactions, stores the data generated, and logs the results. ScenarioRuns allow you to monitor every aspect of the process, including user inputs, variables, and any conditional logic that is applied during the run. Together, Scenarios and ScenarioRuns form a powerful framework for handling dynamic workflows, customer interactions, and automated tasks, all while providing complete tracking and flexibility to adapt based on real-time data. The API is designed to help you automate and optimize processes efficiently, making it a versatile tool for business automation and customer service operations.

Authentication

Working with API Keys

API keys are required for authentication when interacting with scriptRun's API. Each API request must include the API key in the request headers to ensure secure communication between the client and the backend.

To use an API key, include the following header in your requests:

X-API-Key: {api_key}

You can create an API key through the user interface as shown below, or by interacting with the available endpoints.

Steps to Create an API Key

1) Access your profile: Navigate to your profile by clicking on the user icon in the top right corner of the page, as shown in the screenshot below.

Profile Navigation Create API Key

2) View Your API Keys: Once created, your API keys will be listed. You can manage (delete) them as needed. API Key List

3) Create an API Key: In the "API keys" section of your profile, click on the "Create API Key" button. API Key List

4) Copy your API Key: API Key List

Rate Limits

Each API key is associated with a user profile and can be configured with rate limits. These limits control how many requests the API key can make in a given time period.

Rate limits can be defined as follows:

To get permission to send requests through the API, you must request permission from your administrators. To get access and for more information, visit our Telegram channel or send an email to support@scriptrun.ai

Example Usage

You need to include this header in every query:
X-API-Key: <Your_API_Key>
# You can also use wget
curl -X GET https://scriptrun.ai/api/v1/projects/ \
  -H 'Accept: application/json' \
  -H 'X-Api-Key: <Your API Key>' 
import requests
headers = {
  'Accept': 'application/json',
  'x-api-key': '<Your API Key>'
}

r = requests.get('https://scriptrun.ai/api/v1/projects/', headers = headers)

print(r.json())

When making API requests using your API key, be sure to include the following header in every request:

Versioning

The URLs for the various resources use the following pattern:

https://scriptrun.ai/api/v{version}/{operation-specific component}

The components of the URL are: version - the API version. Currently there is only one version, "1", in operation operation-specific component - this identifies the actual operation you want to do. For example a list of projects. Thus the URL getting a list of the project for the authenticated user is https://scriptrun.ai/v1/projects/

Pagination

Example Responses
200 Response
{
  "items": [
    {
      "id": 1,
      "name": "Python Course",
      "total_spent": 0,
      "created_at": "2024-09-26T01:34:43.155232Z",
      "updated_at": "2024-09-26T01:34:43.155236Z",
    }
  ],
  "page": 1,
  "size": 1,
  "total": 1
}
Example Responses
200 Response
{
  "items": [
    {
      "id": 1,
      "name": "Python Course",
      "total_spent": 0,
      "created_at": "2024-09-26T01:34:43.155232Z",
      "updated_at": "2024-09-26T01:34:43.155236Z",
    }
  ],
  "page": 1,
  "size": 1,
  "total": 1
}

All GET endpoints which return an object list support cursor based pagination with pagination information inside a pagination object. Use parameter page and limit to configure pagination. Default limit is set to 10 but values up to 50 are permitted.

Name Description
total Total objects in query
page Page of query
size Number of results per call. Accepted values: 0 - 100. Default 10

Errors

The ScriptRun API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- The object requested is hidden for administrators only.
404 Not Found -- The specified object could not be found.
405 Method Not Allowed -- You tried to access a object with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
410 Gone -- The object requested has been removed from our servers.
418 I'm a teapot.
429 Too Many Requests -- You're requesting too many objects! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.

Projects API

List of Projects

curl -X GET "https://scriptrun.ai/api/v1/projects/?page=1&size=10&name__icontains=test" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/projects/"
headers = {"X-Api-Key": "<Your API Key>"}
params = {"page": 1, "size": 10, "name__icontains": "test"}

response = requests.get(url, headers=headers, params=params)
print(response.json())

GET /api/v1/projects/

Summary: Retrieves a list of projects. Projects track expenses related to rendering prompts and may include various plans (e.g., JustmagicPlan) as well as webhook configurations.

Parameters:

Name In Type Required Description
name__icontains query string No Filter projects by name (case-insensitive match).
page query integer No A page number within the paginated result set.
size query integer No Number of results to return per page.

Responses:

Create a Project

curl -X POST "https://scriptrun.ai/api/v1/projects/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{"name": "New Project", "webhook_url": "https://example.com/webhook/"}'
import requests

url = "https://scriptrun.ai/api/v1/projects/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "name": "New Project",
    "webhook_url": "https://example.com/webhook/"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/projects/

Summary: Creates a new project. A project tracks expenses for prompt rendering and includes webhook settings and various plans.

Request Body:

Responses:

Retrieve a Project

curl -X GET "https://scriptrun.ai/api/v1/projects/123/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/projects/123/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/projects/{id}/

Summary: Retrieves the details of a specific project, including its name, plan, and webhook configuration.

Parameters:

Name In Type Required Description
id path integer Yes A unique integer value identifying the project.

Responses:

Update a Project

curl -X PATCH "https://scriptrun.ai/api/v1/projects/123/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{"name": "Updated Project", "webhook_url": "https://example.com", "is_webhook_enabled": true}'
import requests

url = "https://scriptrun.ai/api/v1/projects/123/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "name": "Updated Project",
    "is_webhook_enabled": True,
    "webhook_url": "https://example.com"
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/projects/{id}/

Summary: Updates the details of a specific project. Only certain fields such as name, total_spent, webhook_url, or is_webhook_enabled can be updated.

Parameters:

Name In Type Required Description
id path integer Yes A unique integer value identifying the project.

Request Body:

Responses:

Delete a Project

curl -X DELETE "https://scriptrun.ai/api/v1/projects/123/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/projects/123/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.delete(url, headers=headers)
print(response.status_code)  # 204 indicates success

DELETE /api/v1/projects/{id}/

Summary: Deletes a specific project by its ID.

Parameters:

Name In Type Required Description
id path integer Yes A unique integer value identifying the project.

Responses:

Scenario and ScenarioRun Relations

Scenario

A Scenario is essentially a blueprint or script that defines a sequence of actions, messages, and workflows. It can be considered a container that holds the logic for a certain process or interaction.

Key Concepts:

  1. Structure: A scenario includes messages, variables, prompts, and conditions. It defines a flow, which can be a conversation, automation task, or other processes.
  2. Messages: Messages are individual units within a scenario. Each message might represent a question, instruction, or data transmission point. Messages can have attached prompts (e.g., input fields, options for users to select), and the logic around which message is sent can depend on conditions.
  3. Variables: Scenarios use variables to store data (e.g., user responses). These variables can be dynamically modified as the scenario is executed, allowing for real-time interaction. For example, you could store a user’s response and use it later in the process.
  4. Prompts: These are user interaction points, like forms or choices. They gather input and conditionally affect how the scenario proceeds. For example, a prompt could ask for a user’s email, and based on the input, different messages could be sent.
  5. Conditions: Scenarios can have conditions that determine the flow. For instance, if a certain variable has a specific value, a different message might be sent, or the flow could branch off into different paths.

Creation and Usage:

ScenarioRun

A ScenarioRun is an execution of a scenario. While a scenario is a template or plan, the ScenarioRun is the actual instance that carries out the process.

Key Concepts:

  1. Execution: When you want to run a scenario, a ScenarioRun instance is created. This instance tracks everything: when it started, how long it ran, the messages that were processed, and any errors that occurred during execution.
  2. Cloning of Data: When a scenario is executed, a ScenarioRun will often copy or clone the variables, messages, and logic from the original scenario. This ensures that any data generated during the run is tied to that specific instance, and the original scenario remains unchanged.
  3. Dynamic Updates: During a ScenarioRun, you can update the messages, variables, or prompts dynamically. This allows flexibility based on user input or other real-time data. For example, if a user inputs certain information, you can update the variable to reflect that and change how the scenario proceeds based on the new data.
  4. Tracking: The ScenarioRun tracks every interaction and result. This includes:
    • Tokens: If using external providers like LLMs (large language models), it tracks the tokens consumed.
    • Cost: It calculates the cost of the run, especially if you’re using external APIs with associated costs.
    • Final Result: After the ScenarioRun completes, a final result (like a summary or final output) is stored.
  5. Webhook Integration: You can provide a webhook_url when running a scenario. Once the ScenarioRun is completed, the system can send the result or status to this webhook, notifying external systems of the result.

Execution Flow:

  1. Initiating a Run: You start a ScenarioRun either from a specific scenario or from an existing run (in case you want to repeat or adjust the previous execution).
  2. Handling Messages: As the run progresses, messages are processed in sequence, and any prompts within them are executed, gathering user input if needed. Conditions can also alter the flow during the run.
  3. Variables and Results: Variables are updated dynamically based on user input or external data. If any error occurs, it’s logged, and the status of the run is updated accordingly.
  4. Finalization: When the ScenarioRun finishes, all results are stored, including any messages, final outputs, or errors. Optionally, the system can send the results to a provided webhook.

Use Cases:

Relationship Between Scenario and ScenarioRun

In simpler terms, you can think of a Scenario as a plan for a journey, and the ScenarioRun as someone actually taking the journey and recording what happens along the way.

Example:

Scenario API

The Scenario API allows you to manage and interact with scripts and their runs (ScenarioRun). A scenario is a blueprint or script that defines a sequence of actions, messages, and workflows, while the ScenarioRun tracks the actual execution of the scenario and the results. This API provides endpoints to create, retrieve, update, and delete scenarios, as well as execute them via a ScenarioRun.

Retrieve Scenarios

import requests

url = "https://scriptrun.ai/api/v1/scenarios/"
headers = {"X-Api-Key": "<Your API Key>"}
params = {"name__icontains": "example", "project": 1, "page": 2}

response = requests.get(url, headers=headers, params=params)
print(response.json())
curl -X GET "https://scriptrun.ai/api/v1/scenarios/?name__icontains=example&project=1&page=2" \
-H "X-Api-Key: <Your API Key>"

GET /api/v1/scenarios/

Summary: Retrieves a list of scenarios with optional filtering.

This endpoint allows users to retrieve a list of scenarios, with options to filter by various parameters such as name, project, or the existence of a ScenarioRun.

Parameters:

Name In Type Required Description
name__icontains query string No Filter scenarios by name (case-insensitive).
page query integer No A page number within the paginated result set.
project query integer No Filter scenarios by project ID.
scenariorun query integer No Filter by ScenarioRun ID.
scenariorun__isnull query boolean No Filter scenarios with or without an associated ScenarioRun.
size query integer No Number of results to return per page.

Responses:

Retrieve a Specific Scenario

import requests

url = "https://scriptrun.ai/api/v1/scenarios/42/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.get(url, headers=headers)
print(response.json())

curl -X GET "https://scriptrun.ai/api/v1/scenarios/42/" \
-H "X-Api-Key: <Your API Key>"

GET /api/v1/scenarios/{id}/

Summary: Retrieves the details of a specific scenario by its ID.

This endpoint retrieves all the details of a specific scenario, including its messages, project information, and other metadata.

Parameters:

Name In Type Required Description
id path integer Yes ID of the scenario to retrieve.

Responses:

Create a Scenario

import requests

url = "https://scriptrun.ai/api/v1/scenarios/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "name": "New Scenario",
    "project": 12,
    "category": 5,
    "run_fee": 50,
    "free_runs_per_user": 3,
    "messages": [1, 2, 3],
    "available_languages": ["en", "ru"],
    "market_title": "Sample Scenario",
    "short_description": "A new scenario example."
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://scriptrun.ai/api/v1/scenarios/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "name": "New Scenario",
  "project": 12,
  "category": 5,
  "subcategory": 5,
  "run_fee": 50,
  "free_runs_per_user": 3,
  "messages": [1, 2, 3],
  "available_languages": ["en", "ru"],
  "market_title": "Sample Scenario",
  "short_description": "A new scenario example."
  "market_permission": "market_available",
  "readme_guide": "Some readme guide"
}'

POST /api/v1/scenarios/

Summary: Creates a new scenario.

This endpoint allows the creation of a new scenario by providing the necessary details, including project, category, messages, and other attributes.

Request Body:

Name Type Required Description
name string Yes The name of the scenario.
project integer Yes The project ID to which this scenario belongs.
category integer Yes Category ID for the scenario.
subcategory integer No Subcategory ID (optional).
run_fee integer Yes Fee percentage for external users (0-999).
free_runs_per_user integer Yes Number of free runs allowed per user.
messages array Yes List of message IDs attached to the scenario.
available_languages array No List of available languages for the scenario.
market_title string No Title for the market if the scenario is available.
short_description string No A brief description of the scenario.
market_permission string No Permission for script.(private or market_available)
readme_guide string No The readme guide of the scenario

Responses:

Update a Scenario

import requests

url = "https://scriptrun.ai/api/v1/scenarios/42/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "name": "Updated Scenario Name",
    "run_fee": 25
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())
curl -X PATCH "https://scriptrun.ai/api/v1/scenarios/42/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "name": "Updated Scenario Name",
  "run_fee": 25
}'

PATCH /api/v1/scenarios/{id}/

Summary: Updates an existing scenario.

This endpoint allows partial updates to a scenario by providing new values for the desired attributes.

Parameters:

Name In Type Required Description
id path integer Yes ID of the scenario to update.

Request Body:

Name Type Required Description
name string No Updated name of the scenario.
run_fee integer No Updated fee percentage for external users.
messages array No Updated list of message IDs attached to the scenario.
available_languages array No Updated list of available languages for the scenario.
market_title string No Updated title for the market if the scenario is available.
short_description string No Updated short description of the scenario.

Responses:

Delete a Scenario

import requests

url = "https://scriptrun.ai/api/v1/scenarios/42/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.delete(url, headers=headers)
print(response.status_code)
curl -X DELETE "https://scriptrun.ai/api/v1/scenarios/42/" \
-H "X-Api-Key: <Your API Key>"

DELETE /api/v1/scenarios/{id}/

Summary: Deletes a specific scenario by its ID.

Parameters:

Name In Type Required Description
id path integer Yes ID of the scenario to delete.

Responses:

ScenarioRun API

A ScenarioRun represents the execution of a scenario. It tracks the details of the run, such as the messages processed, variables updated, and the final result.

Create and Execute a ScenarioRun

import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/run/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "scenario": 42,
    "webhook_url": "https://example.com/webhook",
    "do_run_default": True,
    "messages": [{"id": 1, "key": "newmessagekey1"}],
    "variables": [
        {
            "id": 3,
            "variable_names": [
                {
                    "id": 4,
                    "name": "newname123",
                },
            ],
        },
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://scriptrun.ai/api/v1/scenarioruns/run/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "scenario": 42,
  "webhook_url": "https://example.com/webhook",
  "do_run_default": true,
  "messages": [{"id": 1, "key": "newmessagekey1"}],
  "variables": [{"id": 3,"variable_names": [{"id": 4, "name": "newname123"}]}]
}'

POST /api/v1/scenarioruns/run/

Summary: Executes a scenario or an existing ScenarioRun.

This endpoint creates and starts a ScenarioRun, allowing you to execute a scenario and track the results.

Request Body:

Name Type Required Description
scenario integer Yes ID of the scenario to execute.
webhook_url string No URL to send notifications after the run is completed.
do_run_default boolean No Flag to indicate if the default ScenarioRun should be executed.
messages array No List of updated message data for the run.
variables array No List of updated variables for the run.
inserted_variables array No List of inserted variables for the run.

Responses:

Retrieve a ScenarioRun

import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/42/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.get(url, headers=headers)
print(response.json())

curl -X GET "https://scriptrun.ai/api/v1/scenarioruns/42/" \
-H "X-Api-Key: <Your API Key>"

GET /api/v1/scenarioruns/{id}/

Summary: Retrieves a specific ScenarioRun by ID, including its execution details.

Parameters:

Name In Type Required Description
id path integer Yes ID of the ScenarioRun to retrieve.

Responses:

Update a ScenarioRun

import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/42/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "webhook_url": "https://newexample.com/webhook",
    "do_run_default": False,
    "variables": [{"id": 3, "value": "updated value"}]
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())
curl -X PATCH "https://scriptrun.ai/api/v1/scenarioruns/42/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "webhook_url": "https://newexample.com/webhook",
  "do_run_default": false,
  "variables": [{"id": 3, "value": "updated value"}]
}'

PATCH /api/v1/scenarioruns/{id}/

Summary: Updates an existing ScenarioRun.

This endpoint allows partial updates to a ScenarioRun by providing new values for the desired attributes.

Parameters:

Name In Type Required Description
id path integer Yes ID of the ScenarioRun to update.

Request Body:

Name Type Required Description
webhook_url string No Updated URL to send notifications after the run is completed.
do_run_default boolean No Updated flag to indicate if the default ScenarioRun should be executed.
messages array No Updated list of message data for the run.
variables array No Updated list of variables for the run.
inserted_variables array No Updated list of inserted variables for the run.

Responses:

Delete a ScenarioRun

import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/42/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.delete(url, headers=headers)
print(response.status_code)

curl -X DELETE "https://scriptrun.ai/api/v1/scenarioruns/42/" \
-H "X-Api-Key: <Your API Key>"

DELETE /api/v1/scenarioruns/{id}/

Summary: Deletes a specific ScenarioRun by its ID.

Parameters:

Name In Type Required Description
id path integer Yes ID of the ScenarioRun to delete.

Responses:

Summary: Drafts, Runs, and Re-runs

After a scenario is executed (whether successful or not), the results will either appear in the Final Result or Local Variables, depending on the selected return parameter in the messages.

Update ScenarioRun Inserted Variable

curl -X PATCH "https://scriptrun.ai/api/v1/scenarioruns/42/update-inserted-variable" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "id": <Your scnarionrun inserted_variable id>,
  "variable": <Your scnarionrun variable id,
  "variable_name": <Your scnarionrun variable name 2 id>,
}'
import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/42/update-inserted-variable/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
  "id": "<Your scnarionrun inserted_variable id>",
  "variable": "<Your scnarionrun variable id>",
  "variable_name": "<Your scnarionrun variable name 2 id>",
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/scenarioruns/{id}/update-inserted-variable

Summary: Updates an existing inserted variable for a specific ScenarioRun.

Parameters:

Name In Type Required Description
id path integer Yes ID of the ScenarioRun to update.

Request Body:

Name Type Required Description
id integer Yes ID of the inserted variable to update.
value string Yes Updated value for the inserted variable.

Responses:

Update ScenarioRun Variable

curl -X PATCH "https://scriptrun.ai/api/v1/scenarioruns/42/update-variable" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
    "id": <Your variable id>,
    "key": "new123",
    "variable_names": [
        {
            "id": <Your ScnarionRun variable_name id>,
            "name": "new_name",
            "value": "new_value",
        },
    ],
}'
import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/42/update-variable/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "id": "<ScnarionRun Your variable id>",
    "key": "new123",
    "variable_names": [
        {
            "id": "<Your ScnarionRun variable_name id>",
            "name": "new_name",
            "value": "new_value",
        },
    ],
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/scenarioruns/{id}/update-variable

Summary: Updates an existing variable for a specific ScenarioRun.

Parameters:

Name In Type Required Description
id path integer Yes ID of the ScenarioRun to update.

Request Body:

Name Type Required Description
key string Yes The key of the variable.
project integer Yes ID of the associated project.
variable_names list Yes List of variable names associated with it.

Responses:

Update ScenarioRun Message

curl -X PATCH "https://scriptrun.ai/api/v1/scenarioruns/42/update-message" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
    "id": <Your variable id>,
    "key": "new123",
    "variable_names": [
        {
            "id": <Your variable_name id>,
            "name": "new_name",
            "value": "new_value",
        },
    ],
}'
import requests

url = "https://scriptrun.ai/api/v1/scenarioruns/42/update-message/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {"id": 123, "key": "Updated message key"}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/scenarioruns/{id}/update-message

Summary: Updates an existing message for a specific ScenarioRun.

Parameters:

Name In Type Required Description
id path integer Yes ID of the ScenarioRun to update.

Request Body:

You can check message schema in Create a Message

Responses:

Workflow API Documentation

A Workflow in Slate is a flexible, visual representation of a process or automation. It consists of interconnected nodes (steps, triggers, actions, outputs) and edges (connections between nodes), allowing you to design and execute complex logic flows.

Key Concepts

Workflow Data Structure Example

{
  "id": 6,
  "project": 307,
  "title": "New workflow",
  "data": {
    "edges": [
      {
        "id": "xy-edge__3d63f846-0f6a-478c-b91c-5921259429c1-a67fef47-c844-4489-9024-ff894b5d7465",
        "type": "custom-edge",
        "source": "3d63f846-0f6a-478c-b91c-5921259429c1",
        "target": "a67fef47-c844-4489-9024-ff894b5d7465",
        "style": {"stroke": "#76A9FA", "strokeWidth": 2},
        "animated": false,
        "markerEnd": "edge-target",
        "markerStart": "edge-source"
      }
    ],
    "nodes": [
      {
        "id": "3d63f846-0f6a-478c-b91c-5921259429c1",
        "type": "trigger-node",
        "data": { ... },
        ...
      },
      {
        "id": "a67fef47-c844-4489-9024-ff894b5d7465",
        "type": "basic-node",
        "data": { ... },
        ...
      },
      {
        "id": "2dfa426d-4233-49f2-8532-4b82f57640b6",
        "type": "output-node",
        "data": { ... },
        ...
      }
    ],
    "viewport": {"x": 0.25, "y": 152.25, "zoom": 0.5},
    "start_node": "a67fef47-c844-4489-9024-ff894b5d7465"
  }
}

API Endpoints

Create a Workflow

import requests

url = "https://scriptrun.ai/api/v1/workflows/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "project": 307,
    "title": "New workflow",
    "data": { ... }  # see structure above
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://scriptrun.ai/api/v1/workflows/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "project": 307,
  "title": "New workflow",
  "data": { ... }
}'

POST /api/v1/workflows/

Summary: Creates a new workflow.

Request Body:

Name Type Required Description
project integer Yes Project ID to which the workflow belongs.
title string Yes Name/title of the workflow.
data object Yes Workflow structure (nodes, edges, viewport)

Responses:

Retrieve Workflows

url = "https://scriptrun.ai/api/v1/workflows/"
headers = {"X-Api-Key": "<Your API Key>"}
params = {"project": 307}

response = requests.get(url, headers=headers, params=params)
print(response.json())
curl -X GET "https://scriptrun.ai/api/v1/workflows/?project=307" \
-H "X-Api-Key: <Your API Key>"

GET /api/v1/workflows/

Summary: Retrieves a list of workflows, optionally filtered by project.

Parameters:

Name In Type Required Description
project query integer No Filter workflows by project ID.
title query string No Filter by workflow title (case-insensitive).
page query integer No Page number for pagination.

Responses:

Retrieve a Specific Workflow

url = "https://scriptrun.ai/api/v1/workflows/6/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.get(url, headers=headers)
print(response.json())
curl -X GET "https://scriptrun.ai/api/v1/workflows/6/" \
-H "X-Api-Key: <Your API Key>"

GET /api/v1/workflows/{id}/

Summary: Retrieves the details of a specific workflow by its ID.

Parameters:

Name In Type Required Description
id path integer Yes ID of the workflow to fetch.

Responses:

Update a Workflow

url = "https://scriptrun.ai/api/v1/workflows/6/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
    "title": "Updated Workflow Title",
    "data": { ... }
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())
curl -X PATCH "https://scriptrun.ai/api/v1/workflows/6/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
  "title": "Updated Workflow Title",
  "data": { ... }
}'

PATCH /api/v1/workflows/{id}/

Summary: Updates an existing workflow.

Parameters:

Name In Type Required Description
id path integer Yes ID of the workflow to update.

Request Body:

Name Type Required Description
title string No Updated workflow title.
data object No Updated workflow structure.

Responses:

Delete a Workflow

url = "https://scriptrun.ai/api/v1/workflows/6/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.delete(url, headers=headers)
print(response.status_code)
curl -X DELETE "https://scriptrun.ai/api/v1/workflows/6/" \
-H "X-Api-Key: <Your API Key>"

DELETE /api/v1/workflows/{id}/

Summary: Deletes a specific workflow by its ID.

Parameters:

Name In Type Required Description
id path integer Yes ID of the workflow to delete.

Responses:

Additional Workflow Endpoints

Check Workflow Structure

POST /api/v1/workflows/check_workflow/

Summary: Validates the structure of a workflow before saving or running it.

import requests
url = "https://scriptrun.ai/api/v1/workflows/check_workflow/"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
  "data": {
    "nodes": [...],
    "edges": [...],
    "viewport": {"x": 0, "y": 0, "zoom": 1},
    "start_node": "node-id-1"
  }
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://scriptrun.ai/api/v1/workflows/check_workflow/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "nodes": [...],
      "edges": [...],
      "viewport": {"x": 0, "y": 0, "zoom": 1},
      "start_node": "node-id-1"
    }
  }'

Get Node Schemas for Frontend

GET /api/v1/workflows/get_nodes/

Summary: Retrieves the available node schemas for rendering and configuration in the frontend.

import requests
url = "https://scriptrun.ai/api/v1/workflows/get_nodes/"
headers = {"X-Api-Key": "<Your API Key>"}
response = requests.get(url, headers=headers)
print(response.json())
curl -X GET "https://scriptrun.ai/api/v1/workflows/get_nodes/" \
  -H "X-Api-Key: <Your API Key>"

Run a Workflow

POST /api/v1/workflows/run/

Summary: Starts the execution of a workflow. Requires a task_id as a query parameter.

import requests
url = "https://scriptrun.ai/api/v1/workflows/run/?task_id=123e4567-e89b-12d3-a456-426614174000"
headers = {"X-Api-Key": "<Your API Key>"}
data = {
  "data": {
    "nodes": [...],
    "edges": [...],
    "viewport": {"x": 0, "y": 0, "zoom": 1},
    "start_node": "node-id-1"
  }
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
curl -X POST "https://scriptrun.ai/api/v1/workflows/run/?task_id=123e4567-e89b-12d3-a456-426614174000" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "nodes": [...],
      "edges": [...],
      "viewport": {"x": 0, "y": 0, "zoom": 1},
      "start_node": "node-id-1"
    }
  }'

Get Workflow Node Result

GET /api/v1/workflows/workflow_result/

Summary: Retrieves the result for a specific node in a workflow run.

import requests
url = "https://scriptrun.ai/api/v1/workflows/workflow_result/?task_id=123e4567-e89b-12d3-a456-426614174000&node_id=a67fef47-c844-4489-9024-ff894b5d7465"
headers = {"X-Api-Key": "<Your API Key>"}
response = requests.get(url, headers=headers)
print(response.json())
curl -X GET "https://scriptrun.ai/api/v1/workflows/workflow_result/?task_id=123e4567-e89b-12d3-a456-426614174000&node_id=a67fef47-c844-4489-9024-ff894b5d7465" \
  -H "X-Api-Key: <Your API Key>"

Workflow Run History

GET /api/v1/workflows/history/

Summary: Retrieves the history of workflow runs.

import requests
url = "https://scriptrun.ai/api/v1/workflows/history/?workflow_id=6&limit=10"
headers = {"X-Api-Key": "<Your API Key>"}
response = requests.get(url, headers=headers)
print(response.json())
curl -X GET "https://scriptrun.ai/api/v1/workflows/history/?workflow_id=6&limit=10" \
  -H "X-Api-Key: <Your API Key>"

Workflow Data Structure

Summary

Documents API

The Documents API allows you to manage files uploaded to the system. These files are typically associated with specific projects and can be used in workflows like document recognition. The API supports operations like uploading multiple documents, retrieving document details, updating information, and deleting documents.

List of Documents

curl -X GET "https://scriptrun.ai/api/v1/documents/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/documents/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

Responses:

  {
    "page": 1,
    "total": 2,
    "size": 2,
    "items": [
      {
        "id": 42,
        "project": 1,
        "key": "doc-abc123",
        "filename": "example.pdf",
        "result_file": "example.pdf",
        "result_url": "https://example.com/result.pdf",
        "created_at": "2024-10-03T10:00:00Z",
        "updated_at": "2024-10-03T10:05:00Z"
      },
      {
        "id": 43,
        "project": 1,
        "key": "doc-xyz456",
        "filename": "report.docx",
        "result_file": "report.docx",
        "result_url": "https://example.com/result.docx",
        "created_at": "2024-10-03T11:00:00Z",
        "updated_at": "2024-10-03T11:30:00Z"
      }
    ]
  }

GET /api/v1/documents/

Summary: Retrieves a list of all documents accessible to the authenticated user.

Response Explanation:

Retrieve a Specific Document

curl -X GET "https://scriptrun.ai/api/v1/documents/42/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/documents/42/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/documents/{id}/

Summary: Retrieves the details of a specific document by its ID.

Parameters:

Name In Type Required Description
id path integer Yes The unique ID of the document.

Responses:

Upload Multiple Documents

POST /api/v1/documents/

curl -X POST "https://scriptrun.ai/api/v1/documents/" \
  -H "X-Api-Key: <Your API Key>" \
  -F "file1=@/path/to/example.pdf" \
  -F "file2=@/path/to/report.docx" \
  -F "project=1"
import requests

url = "https://scriptrun.ai/api/v1/documents/"
files = {
    'file1': open('/path/to/example.pdf', 'rb'),
    'file2': open('/path/to/report.docx', 'rb')
}
data = {
    'project': 1
}
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())

Summary: Uploads up to five documents for a specific project.

Request Body:

Name Type Required Description
file1 file No The first file to upload.
file2 file No The second file to upload.
file3 file No The third file to upload.
file4 file No The fourth file to upload.
file5 file No The fifth file to upload.
project integer Yes The ID of the project the documents belong to.

Responses:

Update Document

curl -X PATCH "https://scriptrun.ai/api/v1/documents/42/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "updated-key",
    "filename": "updated-file.pdf"
  }'
import requests

url = "https://scriptrun.ai/api/v1/documents/42/"
data = {
    "key": "updated-key",
    "filename": "updated-file.pdf"
}
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/documents/{id}/

Summary: Updates the metadata or file of a specific document.

Request Body:

Responses:

Delete Document

curl -X DELETE "https://scriptrun.ai/api/v1/documents/42/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/documents/42/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.delete(url, headers=headers)
print(response.status_code)

DELETE /api/v1/documents/{id}/

Summary: Deletes a specific document by its ID.

Parameters:

Name In Type Required Description
id path integer Yes The unique ID of the document to delete.

Responses:

Documents and Recognition Relations

Documents are often used as input for document recognition processes. Once a document is uploaded via the Documents API, it can be linked to a Recognitionrun for processing. During a Recognitionrun, the document is processed, and chunks of recognized content are produced. The API allows full control over both the document upload and the recognition process, making it easy to manage files and automate workflows.

Recognition API

The Recognition API is responsible for managing document recognition runs and their chunks. It allows you to initiate recognition processes, retrieve recognition results, and manage the chunks of data produced during the recognition process.

List of Recognitionruns

{
  "page": 1,
  "total": 2,
  "size": 2,
  "items": [
    {
      "id": 42,
      "project": 1,
      "status": "created",
      "cost": 10.5,
      "chunk_size": 1000,
      "document": 123,
      "created_at": "2024-10-03T10:00:00Z",
      "updated_at": "2024-10-03T10:05:00Z"
    },
    {
      "id": 43,
      "project": 1,
      "status": "finished",
      "cost": 12.0,
      "chunk_size": 2000,
      "document": 124,
      "created_at": "2024-10-03T11:00:00Z",
      "updated_at": "2024-10-03T11:30:00Z"
    }
  ]
}
curl -X GET "https://scriptrun.ai/api/v1/recognitionruns/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/recognitionruns/

Summary: Retrieves a list of all recognition runs accessible to the authenticated user.

Responses:

Retrieve a Specific Recognitionrun

curl -X GET "https://scriptrun.ai/api/v1/recognitionruns/42/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/42/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/recognitionruns/{id}/

Summary: Retrieves the details of a specific recognition run by its ID.

Parameters:

Name In Type Required Description
id path integer Yes The unique ID of the recognition run.

Responses:

Create a Recognitionrun

curl -X POST "https://scriptrun.ai/api/v1/recognitionruns/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "project": 1,
    "chunk_size": 1000,
    "document": 123
  }'
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "project": 1,
    "chunk_size": 1000,
    "document": 123
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/recognitionruns/

Summary: Creates a new recognition run for a project.

Request Body:

Responses:

Enable All Chunks in a Recognitionrun

curl -X POST "https://scriptrun.ai/api/v1/recognitionruns/42/enable-chunks/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/42/enable-chunks/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.post(url, headers=headers)
print(response.json())

POST /api/v1/recognitionruns/{id}/enable-chunks/

Summary: Enables all chunks in the specified recognition run.

Parameters:

Name In Type Required Description
id path integer Yes The unique ID of the recognition run.

Responses:

Disable All Chunks in a Recognitionrun

curl -X POST "https://scriptrun.ai/api/v1/recognitionruns/42/disable-chunks/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/42/disable-chunks/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.post(url, headers=headers)
print(response.json())

POST /api/v1/recognitionruns/{id}/disable-chunks/

Summary: Disables all chunks in the specified recognition run.

Parameters:

Name In Type Required Description
id path integer Yes The unique ID of the recognition run.

Responses:

Enable a Specific Chunk in a Recognitionrun

curl -X POST "https://scriptrun.ai/api/v1/recognitionruns/42/enable-chunk/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 123
  }'
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/42/enable-chunk/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "id": 123
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/recognitionruns/{id}/enable-chunk/

Summary: Enables a specific chunk in the recognition run.

Request Body:

Responses:

Disable a Specific Chunk in a Recognitionrun

curl -X POST "https://scriptrun.ai/api/v1/recognitionruns/42/disable-chunk

/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 123
  }'
import requests

url = "https://scriptrun.ai/api/v1/recognitionruns/42/disable-chunk/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "id": 123
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/recognitionruns/{id}/disable-chunk/

Summary: Disables a specific chunk in the recognition run.

Request Body:

Responses:

Recognitionrun Chunk API

curl -X GET "https://scriptrun.ai/api/v1/recognitionrun-chunks/42/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/recognitionrun-chunks/42/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

Retrieve a Specific Recognitionrun Chunk

GET /api/v1/recognitionrun-chunks/{id}/

Summary: Retrieves the details of a specific recognition run chunk by its ID.

Parameters:

Name In Type Required Description
id path integer Yes The unique ID of the recognition run chunk.

Responses:

Using Recognitionrun and Chunks

These endpoints allow full control over document recognition, including starting recognition runs, managing chunks, and retrieving results.

Prompts and Messages Relations

The Prompts and Messages APIs allow you to manage and interact with prompts and messages within the system. Prompts are user interaction points that gather input and conditionally affect the workflow, while Messages represent individual communication units that can be sent, retrieved, updated, deleted, and reordered. These APIs provide endpoints to create, retrieve, update, delete, and reorder both prompts and messages. The API uses token-based authentication; include your API key in the X-Api-Key header in each request.

Key Concepts

Prompts

A Prompt is an interaction point within a scenario that gathers input from users or performs specific actions based on conditions. Prompts can be simple text inputs, multiple-choice selections, or more complex forms that collect various types of data. They play a crucial role in guiding users through a workflow or conversation, enabling dynamic and interactive experiences.

Structure:

  1. Key: A unique identifier for the prompt within a project.
  2. Role: Defines the role associated with the prompt (e.g., user, system, assistant, positive, negative).
  3. Content: The textual content of the prompt that is presented to the user.
  4. Project: The project to which the prompt belongs.
  5. Prompt Conditions: Conditions that determine when and how the prompt is rendered based on variables or inserted variables.
  6. Attached Prompts: Prompts that are linked to messages, allowing for complex interactions and data collection.
  7. Inserted Variables and Messages: Variables and messages embedded within the prompt content that can be dynamically updated or manipulated.

Key Components:

Messages

A Message is an individual communication unit within a scenario that can represent a question, instruction, or data transmission point. Messages can be looped, sent asynchronously, and have different return types based on the provider used (e.g., text, variables, image). They are essential for structuring the flow of communication within a scenario.

Structure:

  1. Key: A unique identifier for the message within a project.
  2. Project: The project to which the message belongs.
  3. Provider: The AI provider used to generate the message (e.g., openai, claude, gemini, togetherai).
  4. Return Type: The type of content returned by the message (text, variables, image).
  5. Provider-Specific Parameters: Configuration parameters specific to the chosen AI provider (e.g., model name, temperature, max tokens).
  6. Loop Settings: Determines if the message should be looped and how many times.
  7. Attached Prompts: Prompts linked to the message for gathering user input.
  8. Sort ID: Determines the order of the message within the project.

Key Components:

Prompts

Prompts are designed to interact with users, gather input, and influence the flow of messages based on predefined conditions. They serve as the bridge between user inputs and the dynamic behavior of messages within a scenario.

Messages

Messages utilize prompts to create interactive and responsive communication flows. Each message can have multiple attached prompts, allowing for complex interactions where user inputs can dictate subsequent messages or actions.

Interaction Flow:

  1. Message Sends Prompt: A message can trigger one or more prompts to gather input from the user.
  2. User Provides Input: The user interacts with the prompt, providing necessary data or selections.
  3. Condition Evaluation: Based on the input, conditions associated with prompts are evaluated to determine the next steps.
  4. Dynamic Message Flow: Depending on the conditions and user input, different messages may be sent, skipped, or reordered, creating a dynamic and personalized experience.

Example Workflow:

  1. Message 1: Sends a greeting to the user.
  2. Prompt 1: Asks the user for their name.
  3. Message 2: Greets the user by name using the input from Prompt 1.
  4. Prompt 2: Asks the user how they can be assisted.
  5. Condition: If the user requests a password reset, send Message 3; otherwise, send Message 4.
  6. Message 3: Provides password reset instructions.
  7. Message 4: Offers general assistance based on user input.

Prompts and Messages API Reference

Messages API Endpoints

Prompts API Endpoints

Conclusion

The Prompts and Messages APIs provide a comprehensive framework for creating dynamic, interactive workflows within your projects. By leveraging these APIs, you can build sophisticated scenarios that respond to user inputs, adapt based on conditions, and integrate seamlessly with various AI providers to deliver personalized and effective user experiences.

For more detailed information on specific endpoints, parameters, and usage examples, refer to the respective API sections above.

Messages API

This documentation describes the API endpoints for managing messages in the system. You can use these endpoints to create, retrieve, update, delete, and reorder messages. The API uses token-based authentication; include your API key in the X-Api-Key header in each request.

List of Messages

curl -X GET "https://scriptrun.ai/api/v1/messages/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/messages/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/messages/

Summary: Retrieves a list of all messages accessible to the authenticated user.

Parameters:

Name Type Description
page integer Page number for pagination.
page_size integer Number of items per page.

Responses:

Retrieve a Message

curl -X GET "https://scriptrun.ai/api/v1/messages/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/messages/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/messages/{id}/

Summary: Retrieves the details of a specific message by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the message.

Responses:


Create a Message

curl -X POST "https://scriptrun.ai/api/v1/messages/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "unique_key",
    "project": 1,
    "provider": "openai",
    "return_type": "text",
    "openai_model": "gpt-4",
    "openai_temperature": 0.7,
    "prompts": [1, 2],
}'
import requests

url = "https://scriptrun.ai/api/v1/messages/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "key": "unique_key",
    "project": 1,
    "provider": "openai",
    "return_type": "text",
    "openai_model": "gpt-4",
    "openai_temperature": 0.7
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/messages/

Summary: Creates a new message.

Request Body:

Name Type Required Description
key string Yes Unique key for the message within the project.
project integer Yes ID of the project to which the message belongs.
provider string Yes Provider name (e.g., openai, claude).
return_type string Yes Type of the return value (text, variables, image).
prompts array Yes List of prompts ids
Provider-specific parameters (see below).

Provider-Specific Parameters:

Name Type Required Description
openai_model string Yes Model name (e.g., gpt-4).
openai_temperature float No Sampling temperature. Default: 0.7.
openai_max_tokens integer No Maximum number of tokens.
Name Type Required Description
claude_model string Yes Model name.
claude_temperature float No Sampling temperature. Default: 1.0.
claude_max_tokens integer No Maximum number of tokens.

Responses:

Update a Message

curl -X PATCH "https://scriptrun.ai/api/v1/messages/1/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "openai_temperature": 0.9
}'
import requests

url = "https://scriptrun.ai/api/v1/messages/1/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "openai_temperature": 0.9
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/messages/{id}/

Summary: Updates an existing message.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the message.

Request Body:

Responses:



Delete a Message

curl -X DELETE "https://scriptrun.ai/api/v1/messages/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/messages/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.delete(url, headers=headers)
print(response.status_code)

DELETE /api/v1/messages/{id}/

Summary: Deletes a message.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the message.

Responses:

Reorder Messages

curl -X POST "https://scriptrun.ai/api/v1/messages/1/reorder/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "sort_id": 2
}'
import requests

url = "https://scriptrun.ai/api/v1/messages/1/reorder/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "sort_id": 2
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/messages/{id}/reorder/

Summary: Changes the sorting order of a message within its project.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the message.

Request Body:

Name Type Required Description
sort_id integer Yes New position index for the message.

Responses:

List of Available Models

curl -X GET "https://scriptrun.ai/api/v1/messages/models/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/messages/models/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())
//Example response
[
  {
    "slug": "claude-3-5-sonnet-20240620",
    "label": "claude-3-5-sonnet-20240620",
    "provider": "claude",
    "max_tokens": 8192,
    "temperature": {
      "min": 0,
      "max": 1,
      "default": 1
    },
    "frequency_penalty": null,
    "presence_penalty": null
  },
  {
    "slug": "claude-3-haiku-20240307",
    "label": "claude-3-haiku-20240307",
    "provider": "claude",
    "max_tokens": 4096,
    "temperature": {
      "min": 0,
      "max": 1,
      "default": 1
    },
    "frequency_penalty": null,
    "presence_penalty": null
  },
  {
    "slug": "gemini-1.5-flash",
    "label": "gemini-1.5-flash",
    "provider": "gemini",
    "max_tokens": 8192,
    "temperature": {
      "min": 0,
      "max": 2,
      "default": 1
    },
    "frequency_penalty": null,
    "presence_penalty": null
  },
  {
    "slug": "gemini-1.5-pro",
    "label": "gemini-1.5-pro",
    "provider": "gemini",
    "max_tokens": 8192,
    "temperature": {
      "min": 0,
      "max": 2,
      "default": 1
    },
    "frequency_penalty": null,
    "presence_penalty": null
  },
  ... and others
]

GET /api/v1/messages/models/

Summary: Retrieves a list of available AI models along with their parameters and constraints.

Responses:

Name Type Description
slug string Unique identifier for the model.
label string Human-readable name of the model.
provider string Provider name (e.g., openai, claude).
max_tokens integer Maximum token limit for the model.
temperature float Supported temperature range.
frequency_penalty float Supported frequency penalty range.
presence_penalty float Supported presence penalty range.

Message Fields

Common Fields

Provider-Specific Fields

OpenAI Fields

Claude Fields

Gemini Fields

TogetherAI Fields

You can check all validation conditions in List of Available Models

Stability Fields

Prompts API

This documentation describes the API endpoints for managing prompts in the system. You can use these endpoints to create, retrieve, update, delete, and reorder prompts. The API uses token-based authentication; include your API key in the X-Api-Key header in each request.

List of Prompts

curl -X GET "https://scriptrun.ai/api/v1/prompts/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/prompts/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/prompts/

Summary: Retrieves a list of all prompts accessible to the authenticated user.

Parameters:

Name Type Description
key string Filters prompts by key (case-insensitive).
project integer Filters prompts by project ID.
scenariorun boolean Filters by scenario run (exact or is null).

Responses:

Retrieve a Prompt

curl -X GET "https://scriptrun.ai/api/v1/prompts/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/prompts/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/prompts/{id}/

Summary: Retrieves the details of a specific prompt by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the prompt.

Responses:


- 404 Not Found:

Create a Prompt

POST /api/v1/prompts/

curl -X POST "https://scriptrun.ai/api/v1/prompts/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "api_key_prompt",
    "role": "user",
    "content": "Please enter your API key: <variable>-1,40330,274261</variable> \nImportant: <message>0,7010</message>",
    "project": 1,
    "prompt_conditions": [
      {
        "is_enabled": true,
        "type": "variable",
        "matching": "equal",
        "value": "example_value",
        "action": "skip"
      }
    ]
  }'
import requests

url = "https://scriptrun.ai/api/v1/prompts/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "key": "api_key_prompt",
    "role": "user",
    "content": "Please enter your API key: <variable>-1,40330,274261</variable> \nImportant: <message>0,7010</message>",
    "project": 1,
    "prompt_conditions": [
      {
        "is_enabled": True,
        "type": "variable",
        "matching": "equal",
        "value": "example_value",
        "action": "skip"
      }
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

Summary: Creates a new prompt.

Request Body

Name Type Required Description
key string Yes Unique key for identifying the prompt.
role string Yes The role of the prompt (e.g., user, system).
content string Yes The content of the prompt.
project integer No ID of the associated project.
prompt_conditions array No List of conditions under which the prompt is rendered.

About prompt_conditions

prompt_conditions is an optional array of conditions that define when the prompt will be executed or rendered. Each condition is an object that can contain the following fields:

Embedding Variables and Messages

To enhance the interactivity of your prompts, you can embed variables and messages within the content field using specific placeholders. These placeholders allow dynamic insertion of values and display of conditional messages.

Variable Placeholder

Use the <variable> tag to insert a variable into your prompt content. The format is:

<variable>-1,{variable_id},{variable_name_id}</variable>
Please enter your API key: <variable>-1,40330,274261</variable>

Message Placeholder

Use the <message> tag to insert a message into your prompt content. The format is:

<message>0,{message_id}</message>
Important: <message>0,7010</message>

Update a Prompt

curl -X PATCH "https://scriptrun.ai/api/v1/prompts/1/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Updated content"
  }'
import requests

url = "https://scriptrun.ai/api/v1/prompts/1/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "content": "Updated content"
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/prompts/{id}/

Summary: Updates the details of an existing prompt.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the prompt.

Request Body (partial):

Name Type Required Description
key string No Unique key for identifying the prompt.
role string No The role of the prompt.
content string No The content of the prompt.
prompt_conditions array No List of conditions to update.

Responses:

Delete a Prompt

curl -X DELETE "https://scriptrun.ai/api/v1/prompts/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/prompts/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.delete(url, headers=headers)
print(response.status_code)

DELETE /api/v1/prompts/{id}/

Summary: Deletes a specific prompt by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the prompt.

Responses:

Reorder a Prompt

curl -X POST "https://scriptrun.ai/api/v1/prompts/1/reorder/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "sort_id": 2
  }'
import requests

url = "https://scriptrun.ai/api/v1/prompts/1/reorder/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "sort_id": 2
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/prompts/{id}/reorder/

Summary: Reorders the specified prompt by updating its sort_id.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the prompt.

Request Body:

Name Type Required Description
sort_id integer Yes The new sorting order ID.

Responses:

Variables API

The Variables API is used to create and manage variables that store keyword data. These variables can be integrated into system prompts dynamically, adapting their content based on keywords or clusters generated from Keywordrun.

List of Variables

curl -X GET "https://scriptrun.ai/api/v1/variables/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/variables/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/variables/

Summary: Retrieves a list of all variables accessible to the authenticated user.

Responses:

Create a Variable

curl -X POST "https://scriptrun.ai/api/v1/variables/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "example_keyword_variable",
    "project": 1,
    "variable_names": [
      {
        "name": "Keyword Cluster 1",
        "value": "example keyword 1, example keyword 2",
        "is_active": true
      },
      {
        "name": "Keyword Cluster 2",
        "value": "example keyword 3",
        "is_active": false
      }
    ]
  }'
import requests

url = "https://scriptrun.ai/api/v1/variables/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "key": "example_keyword_variable",
    "project": 1,
    "variable_names": [
        {
            "name": "Keyword Cluster 1",
            "value": "example keyword 1, example keyword 2",
            "is_active": True
        },
        {
            "name": "Keyword Cluster 2",
            "value": "example keyword 3",
            "is_active": False
        }
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/variables/

Summary: Creates a new variable to store keyword or cluster data, which can be used in prompts.

Request Body:

Name Type Required Description
key string Yes The key of the variable.
project integer Yes ID of the associated project.
variable_names list Yes List of variable names associated with it.

Responses:

Update a Variable

curl -X PATCH "https://scriptrun.ai/api/v1/variables/1/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
            "key": "test",
            "keywordrun": None,
            "keywordrun_mode": "",
            "variable_names": [
                {
                    "name": "test",
                    "value": "",
                    "is_active": True,
                },
            ],
            "project": project.id,
        }'
import requests

url = "https://scriptrun.ai/api/v1/variables/1/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "key": "test",
    "keywordrun": None,
    "keywordrun_mode": "",
    "variable_names": [
        {
            "name": "test",
            "value": "",
            "is_active": True,
        },
    ],
    "project": project.id,
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/variables/{id}/

Summary: Updates a specific variable.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the variable.

Request Body:

Name Type Required Description
key string No Updated key for the variable.
variable_names list No Updated list of variable names.

Responses:

Delete a Variable

curl -X DELETE "https://scriptrun.ai/api/v1/variables/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/variables/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.delete(url, headers=headers)
print(response.status_code)

DELETE /api/v1/variables/{id}/

Summary: Deletes a specific variable by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the variable.

Responses:

Reorder a Variable

curl -X POST "https://scriptrun.ai/api/v1/variables/1/reorder/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "sort_id": 5
  }'
import requests

url = "https://scriptrun.ai/api/v1/variables/1/reorder/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {"sort_id": 5}

response = requests.post(url, headers=headers, json=data)
print(response.status_code)

POST /api/v1/variables/{id}/reorder/

Summary: Updates the order of a specific variable.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the variable.

Request Body:

Name Type Required Description
sort_id integer Yes The new sort order for the variable.

Responses:

Retrieve Project Stopwords

curl -X GET "https://scriptrun.ai/api/v1/projects/123/get-stopwords/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/projects/123/get-stopwords/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/projects/{id}/get-stopwords/

Summary: Retrieves the stopwords associated with a specific project.

Parameters:

Name In Type Required Description
id path integer Yes A unique integer value identifying the project.

Responses:

Set Project Stopwords

curl -X POST "https://scriptrun.ai/api/v1/projects/123/set-stopwords/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{"stopwords": ["stopword1", "stopword2"]}'
import requests

url = "https://scriptrun.ai/api/v1/projects/123/set-stopwords/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {"stopwords": ["stopword1", "stopword2"]}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/projects/{id}/set-stopwords/

Summary: Updates the list of stopwords associated with a specific project.

Parameters:

Name In Type Required Description
id path integer Yes A unique integer value identifying the project.

Request Body:

Responses:

Keywords API

The Keywords API allows you to manage and retrieve individual keywords that are used in the system for content extraction, search engine optimization, or any other automated keyword-based operations.

List of Keywords

curl -X GET "https://scriptrun.ai/api/v1/keywords/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywords/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/keywords/

Summary: Retrieves a list of all keywords accessible to the authenticated user.

Parameters (optional):

Name Type Description
project integer Filters keywords by associated project ID.

Responses:

Retrieve a Keyword

curl -X GET "https://scriptrun.ai/api/v1/keywords/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywords/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/keywords/{id}/

Summary: Retrieves the details of a specific keyword by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword.

Responses:

Create a Keyword

curl -X POST "https://scriptrun.ai/api/v1/keywords/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "example_keyword",
    "project": 1,
    "volume": 1000,
    "competitor_url": "https://competitor.com",
    "mode": "serp"
    "keyword_cluster": none,
  }'
import requests

url = "https://scriptrun.ai/api/v1/keywords/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "name": "example_keyword",
    "project": 1,
    "volume": 1000,
    "competitor_url": "https://competitor.com",
    "mode": "serp",
    "keyword_cluster": None, 
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/keywords/

Summary: Creates a new keyword.

Request Body:

Name Type Required Description
name string Yes The name of the keyword.
project integer Yes ID of the associated project.
volume integer No Search volume for the keyword.
competitor_url string No URL of competitor for the keyword.
mode string No Mode for keyword (e.g., serp, question).
keyword_cluster integer Yes Keyword cluster id or None

Responses:

Update a Keyword

curl -X PATCH "https://scriptrun.ai/api/v1/keywords/1/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "updated_keyword_name",
    "volume": 2000
  }'
import requests

url = "https://scriptrun.ai/api/v1/keywords/1/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "name": "updated_keyword_name",
    "volume": 2000
}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/keywords/{id}/

Summary: Updates a specific keyword.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword.

Request Body:

Name Type Required Description
name string No The new name of the keyword.
volume integer No Updated search volume.
competitor_url string No Updated competitor URL.

Responses:

Delete a Keyword

curl -X DELETE "https://scriptrun.ai/api/v1/keywords/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywords/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.delete(url, headers=headers)
print(response.status_code)

DELETE /api/v1/keywords/{id}/

Summary: Deletes a specific keyword by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword.

Responses:

Keywordrun API

The Keywordrun API is responsible for managing keyword extraction processes. You can create, update, delete, reorder, clusterize keyword runs based on a topic or a URL, and then group or cluster these keywords for future use in other parts of the system.

List of Keyword Runs

curl -X GET "https://scriptrun.ai/api/v1/keywordruns/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/keywordruns/

Summary: Retrieves a list of all keyword runs accessible to the authenticated user.

Parameters (optional):

Name Type Description
project integer Filters keyword runs by associated project ID.

Responses:

Retrieve a Keyword Run

curl -X GET "https://scriptrun.ai/api/v1/keywordruns/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.get(url, headers=headers)
print(response.json())

GET /api/v1/keywordruns/{id}/

Summary: Retrieves the details of a specific keyword run by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword run.

Responses:

Create a Keyword Run

curl -X POST "https://scriptrun.ai/api/v1/keywordruns/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "project": 1,
    "topic": "example topic",
    "do_clusterize": true
  }'
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {
    "project": 1,
    "topic": "example topic",
    "do_clusterize": True
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

POST /api/v1/keywordruns/

Summary: Creates a new keyword run for a project.

Request Body:

Name Type Required Description
project integer Yes The ID of the associated project.
topic string No Topic for keyword extraction (optional).
url string No URL for keyword extraction (optional).
preset integer No Keyword run preset.
do_clusterize boolean No Indicates whether to clusterize keywords.

Note: Either topic or url must be provided in the request.

Responses:

Update a Keyword Run

curl -X PATCH "https://scriptrun.ai/api/v1/keywordruns/1/" \
  -H "X-Api-Key: <Your API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "preset": 2
  }'
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/1/"
headers = {
    "X-Api-Key": "<Your API Key>",
    "Content-Type": "application/json"
}
data = {"preset": 2}

response = requests.patch(url, headers=headers, json=data)
print(response.json())

PATCH /api/v1/keywordruns/{id}/

Summary: Updates a specific keyword run.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword run.

Request Body:

Name Type Required Description
preset integer No Updated preset for the keyword run.

Responses:

Delete a Keyword Run

curl -X DELETE "https://scriptrun.ai/api/v1/keywordruns/1/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/1/"
headers = {
    "X-Api-Key": "<Your API Key>"
}

response = requests.delete(url, headers=headers)
print(response.status_code)

DELETE /api/v1/keywordruns/{id}/

Summary: Deletes a specific keyword run by its ID.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword run.

Responses:

Clusterize a Keyword Run

curl -X POST "https://scriptrun.ai/api/v1/keywordruns/1/clusterize/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/1/clusterize/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.post(url, headers=headers)
print(response.status_code)

POST /api/v1/keywordruns/{id}/clusterize/

Summary: Clusters keywords from a specific keyword run.

Parameters:

Name Type Required Description
id integer Yes A unique integer identifying the keyword run.

Responses:

Enable All Keywords in Keyword Run

curl -X POST "https://scriptrun.ai/api/v1/keywordruns/1/enable_all/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/1/enable_all/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.post(url, headers=headers)
print(response.status_code)

POST /api/v1/keywordruns/{id}/enable_all/

Summary: Enables all keywords in a specific keyword run.

Responses:

Disable All Keywords in Keyword Run

curl -X POST "https://scriptrun.ai/api/v1/keywordruns/1/disable_all/" \
  -H "X-Api-Key: <Your API Key>"
import requests

url = "https://scriptrun.ai/api/v1/keywordruns/1/disable_all/"
headers = {"X-Api-Key": "<Your API Key>"}

response = requests.post(url, headers=headers)
print(response.status_code)

POST /api/v1/keywordruns/{id}/disable_all/

Summary: Disables all keywords in a specific keyword run.

Responses:

Keywords and Variables Relations

Relationship Overview

  1. Keywords and Keywordrun: These entities are used to manage keywords, group them into clusters (through Keywordrun), and initiate processes for extracting keyword phrases.
  2. Variables: Variables are crucial in allowing results from keyword runs to be used dynamically in system prompts. They store keywords or clusters, which can then be inserted into prompts, adapting content based on conditions or context.

Workflow

  1. Keywordrun Process: A Keywordrun initiates a process to extract keywords for a specific project. The process can be based on either a topic or a URL. Once completed, keyword results can be grouped into clusters.
  2. Using Keywords in Variables: Once a Keywordrun is complete, the resulting Keywords can be associated with specific Variables. These variables store either individual keywords or keyword clusters, which can then be used dynamically in system prompts.
  3. Inserted Variables in Prompts: Inserted variables use the keyword data to dynamically generate prompt content. For example, based on a user's query, specific keywords or clusters may be inserted into a prompt.

Example Relations Workflow

# Create Keywordrun and Extract Keywords
curl -X POST "https://scriptrun.ai/api/v1/keywordruns/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
    "project": 1,
    "topic": "example topic",
    "do_clusterize": true
}'
# Assign Keywords to Variables
curl -X POST "https://scriptrun.ai/api/v1/variables/" \
-H "X-Api-Key: <Your API Key>" \
-H "Content-Type: application/json" \
-d '{
    "key": "example_keyword_variable",
    "project": 1,
    "is_global": false,
    "variable_names": [
      {
        "name": "Keyword Cluster 1",
        "value": "example keyword 1, example keyword 2",
        "is_active": true
      },
      {
        "name": "Keyword Cluster 2",
        "value": "example keyword 3",
        "is_active": false
      }
    ]
}'
// Using Variables in Prompts
{
  "key": "example_prompt",
  "role": "user",
  "content": "Here are some suggested keywords: {{ example_keyword_variable }}",
  "project": 1,
  "prompt_conditions": [
    {
      "is_enabled": true,
      "type": "variable",
      "matching": "equal",
      "value": "active",
      "action": "skip"
    }
  ]
}
import requests
import json

api_key = "<Your API Key>"

url = "https://scriptrun.ai/api/v1/variables/"

headers = {
    "X-Api-Key": api_key,
    "Content-Type": "application/json"
}

payload = {
    "key": "example_keyword_variable",
    "project": 1,
    "is_global": False,
    "variable_names": [
        {
            "name": "Keyword Cluster 1",
            "value": "example keyword 1, example keyword 2",
            "is_active": True
        },
        {
            "name": "Keyword Cluster 2",
            "value": "example keyword 3",
            "is_active": False
        }
    ]
}

response = requests.post(url, headers=headers, json=payload)

  1. Create Keywordrun and Extract Keywords:

    • You start by creating a Keywordrun for a project, using either a topic or a URL.
    • The Keywordrun API retrieves keywords and saves them as Keyword objects in the database, where they can be classified and sorted.


  2. Assign Keywords to Variables:

    • Once keywords are extracted and clustered, they can be linked to a Variable. This allows dynamic keyword data to be used in system prompts.
    • Here, you create a variable that holds a list of keywords grouped by cluster.


  3. Using Variables in Prompts:

    • Now you can use the created variable in your prompts. For instance, a prompt can dynamically include keywords or keyword clusters based on the user’s query.