Actions20
- Assistant Actions
- Embedding Actions
- File Actions
- Report Actions
- Text Actions
- Thread Actions
Overview
The "Create and Run Thread" operation in this OpenAI Analytics node allows users to create a new conversational thread, add one or multiple messages to it, optionally attach files, run the thread with a selected assistant, and wait for the completion of the run to obtain results. This operation is useful for automating interactions with AI assistants where you want to start a fresh conversation, provide initial context or multiple messages, and immediately get the assistant's response.
Common scenarios include:
- Starting a new chat session with an AI assistant with predefined messages.
- Running a thread that includes file attachments (e.g., documents or data) to provide additional context.
- Automating workflows that require synchronous execution, waiting for the assistant's output before proceeding.
- Overriding default system instructions for customized assistant behavior.
Practical example:
- A user wants to create a support ticket conversation by sending an initial message describing the issue, attaching relevant logs as files, running the thread through a specific assistant configured for support, and retrieving the assistant’s response immediately.
Properties
Name | Meaning |
---|---|
Authentication | Choose which API credentials to use: either dedicated OpenAI Analytics API credentials or existing OpenAI API credentials. |
Message Input Method | Select how to input messages into the thread: "Single Message" to add only one initial message, or "Multiple Messages" to add several messages with specified roles (user or system). |
Initial Message | The single initial message content to add to the thread (required if using Single Message input method). |
Messages | A list of messages to add to the thread when using Multiple Messages input method. Each message includes a role ("User" or "System") and content text (required). |
File Attachment Method | How to attach files to the thread: use existing uploaded file IDs, upload binary files from the previous node, use both methods, or no file attachments. |
Binary Property | The name of the binary property containing file data from the previous node (required if uploading files). |
File Purpose | Purpose of uploaded files: for use with assistants or as input to assistants. |
Enable File Attachments | Whether to attach existing uploaded files (boolean). |
File IDs | List of existing file IDs to attach to the thread (only shown if attaching existing files and enabled). |
Select Assistant | How to select the assistant to run the thread: choose from a list or enter an assistant ID manually. |
Assistant | The assistant selected from the list to use for the run (required if selecting from list). |
Assistant ID | The ID of the assistant to use for the run (required if entering by ID). |
Wait for Completion | Whether to wait for the thread run to complete before returning the result (boolean). |
Maximum Poll Time (Seconds) | Maximum time in seconds to wait for the run to complete if waiting for completion. |
Instructions | Optional override for the default system instructions of the assistant. |
Simplify Output | Whether to return a simplified response format instead of the full detailed output (boolean). |
Output
The node outputs the result of creating and running the thread. The main output is a JSON object containing details about the thread run, including:
- The thread ID and run ID.
- The messages exchanged in the thread.
- The assistant's responses.
- Status information about the run.
- If
Simplify Output
is enabled, the response is returned in a simplified format focusing on essential data.
If files are involved, the node may handle binary data uploads but does not output binary data itself; rather, it references file IDs.
Dependencies
- Requires valid API credentials for OpenAI Analytics API or OpenAI API.
- Needs network access to OpenAI endpoints.
- For file uploads, expects binary data from previous nodes in the workflow.
- Uses OpenAI SDK client initialized with the provided credentials.
- The node relies on internal helper modules for handling threads, assistants, files, text, embeddings, and reports.
Troubleshooting
- Credential Errors: If credentials are missing or invalid, the node will fail to authenticate. Ensure correct API keys and optional organization IDs are set up in n8n credentials.
- File Attachment Issues: When uploading files, ensure the binary property name matches the incoming binary data. Also, verify that file IDs used exist and are accessible.
- Assistant Selection: Selecting an assistant by ID requires a valid assistant ID. Using the list option depends on successful retrieval of available assistants.
- Timeouts: If
Wait for Completion
is enabled, the node polls for run completion up to the maximum poll time. Long-running runs might exceed this timeout, causing incomplete results. - Message Input Validation: When using multiple messages, each message must have a role and non-empty content. Missing required fields will cause errors.
- API Rate Limits: Frequent calls to OpenAI APIs may hit rate limits; consider adding delays or error handling for retries.
Links and References
- OpenAI API Documentation
- OpenAI Analytics API Overview
- n8n Documentation - Creating Custom Nodes
- OpenAI Node.js SDK
This summary is based solely on static analysis of the provided source code and property definitions without runtime execution.