API

Integrate your interface as an API.

Once your flow is ready for production, you can deploy it as an API. Just click on deploy to get a production-ready version of your model.

Get your RestAPI

To obtain your API just go to the Export View and select API.

In this section, you will receive a code snippet to call your flow via a POST request in Python, JavaScript, and cURL.

import requests

API_URL = f"https://stack-inference.com/inference/v0/run/<YOUR_ORG_ID>/<YOUR_FLOW_ID>"
headers = {'Authorization':
 'Bearer YOUR_PUBLIC_KEY',
 'Content-Type': 'application/json'
}

def query(payload):
 response = requests.post(API_URL, headers=headers, json=payload)
 return response.json()

# you can add all your inputs here:
body = {'in-0': 'text for in-0', 'audio2text-0': 'base64 of audio to send',
'string-0': 'long string to send', 'url-0': 'url of website to load'}

output = query(body)

Some quick facts:

  • This request receives all the inputs to the LLM as the body.

  • This request returns the value of all the outputs to the LLM as a JSON.

  • The API supports auto-scaling for a large volume of requests.

  • Stack protects this API with the Token of your organization

Uploading Documents via API

To get started, create a workflow that has a Files Node as one of the inputs.

To make API calls, you’ll need the following information:

  • user_id: Your user ID with a handle for the specific conversation (user_id-conversation_id)

  • org: Your organization id

  • flow_id: The ID of your project

  • node_id: The ID of your Document Node (defaults to doc-0 if you have only one Document Node)

These parameters are used to uniquely identify where to store and associate uploaded documents within your Stack AI workspace.

API Endpoint

Stack AI’s API endpoints allow you to programmatically upload documents, enabling seamless integration with your applications and automation of the upload process. Before making API calls, you’ll need to obtain your API Keys. Navigate to Settings -> API Keys to generate your credentials. Once you have your credentials (a public API Key) and understand the required parameters, you can do your first call.

Example API Call

Here’s an example of how to upload a document using cURL:

curl -X POST "https://api.stack-ai.com/upload_to_supabase_user?org=your-organization&user_id=your-user-id&flow_id=your-flow-id&node_id=doc-0"
-H "Authorization: Bearer YOUR_API_KEY"
-F "file=@/path/to/your/document.pdf"

Last updated

Was this helpful?