> ## Content Index
> Fetch the complete content index at: https://help.cuedesk.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# OpenAI Integration Guide
- URL: https://help.cuedesk.com/openai-integration-guide/
- Published: 2025-07-09T10:15:35.000Z
- Updated: 2026-10-29T13:10:07.000Z
- Author: Rhett Trickett
- Tags: Integrations

![](https://help.cuedesk.com/content/images/2026/10/cue-openai-integration-guide-hero.png)

This guide will cover how to integrate OpenAI's powerful AI capabilities directly into your Cue flows. You can use OpenAI for chat completions, function calling, and structured responses to enhance your customer service automation across WhatsApp, WebChat, and Messenger channels.

| Functionality                | Possible | Notes               |
| ---------------------------- | -------- | ------------------- |
| Create a function call       | ✅        | using chatbot flows |
| Create a web search response | ✅        | using chatbot flows |
| Create an image response     | ✅        | using chatbot flows |

## Overview

- [Requirements for integration](#requirements-for-integration)
- [Setting up OpenAI API access](#setting-up-openai-api-access)
- [Chat Completion integration](#chat-completion-integration)
- [Function Calling integration](#function-calling-integration)

## Requirements for integration

- A Cue account with access to manage flows
- An OpenAI API account with valid API key
- Understanding of JSON formatting for API requests
- Basic knowledge of Cue's Flow Builder and HTTP request nodes

## Setting up OpenAI API access

Before integrating with Cue, you'll need to set up your OpenAI API access:

1. Sign up for an OpenAI account at [platform.openai.com](https://platform.openai.com/?ref=help.cuedesk.com)
2. Navigate to the API Keys section
3. Create a new API key and copy it securely
4. Add credits to your account for API usage

**Important**: Keep your API key secure and never expose it in client-side code or public repositories.

## Chat Completion Integration

In this section we’ll show how to use a simple Chat Completion to summarize the entire bot-to-customer conversation at the end of a Cue flow, then hand it off—either to a live agent or to an external system (CRM, ticketing, etc.).

When to use Chat Completion

- Summarize a multi-step chatbot interaction for a human agent
- Generate a plain-text recap for logging or archival

### Stringify the Conversation

1. **Open your flow** in the Cue Flow Builder
2. **Add a Function step**
3. **Configure the Input** `{"conversation":"{{session.conversation.plainText}}"}`
4. **Save result as:** `conversationString`
5. **Code:**

```javascript
module.exports = function main(input) {
  const convoString = JSON.stringify(input.conversation)
  return convoString;  
}
```

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-07-09-at-09.22.15.png)

### Basic HTTP Setup

1. **Open your flow** in the Cue Flow Builder
2. **Add an HTTP request step** where you want the summarisation to occur.
3. **Save response as:** `aiSummary`
4. **Configure the HTTP request** with the following settings:
5. **URL**: `https://api.openai.com/v1/chat/completions`
6. **Method**: `POST`
7. **Authorization:** `Bearer Token`
8. **Token:** `ExampleToken`
9. **Body:**

```json
{
  "model": "gpt-4.1-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are an assistant who summarizes customer support conversations. Produce a concise plain-text summary. Keep it short and to the point."
    },
    {
      "role": "user",
      "content": "Can you please summarize the following: \"{{session.conversationString.output}}\""
    }
  ]
}
```

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-07-09-at-09.22.58.png)

1. **Add a Set node.**
2. **Save result as:** `summary`
3. **Value**: `{{session.aiSummary.body}}`
4. **JSON Path Query:** `$.choices[0].message.content`
5. **JSON Return Type:** `single`

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-07-09-at-09.24.48.png)

### **Push to External API**

- Add another HTTP Request node:
- **URL**: `your-crm.example.com/api/tickets`
- **Method**: `POST`
- **Body:**

```json
{
  "summary": "{{session.summary}}"
}
```

1. Error Handling
- In your HTTP node, check `{{session.response.statusCode}} == 200`
- On success → parse and continue
- On failure → set a fallback message or skip summarization
1. Best Practices
- Keep your system prompt as concise as possible
- Avoid sending sensitive PII—mask or truncate as needed

## Function Calling Integration

Function calling allows OpenAI to determine when to call specific functions based on the conversation context. This is ideal for categorizing queries.

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-05-29-at-09.47.30.png)

### Basic Setup

1. **Open your flow** in the Cue Flow Builder
2. **Add an HTTP request node** where you want the AI interaction to occur
3. **Configure the HTTP request** with the following settings:
- **URL**: `https://api.openai.com/v1/chat/completions`
- **Method**: `POST`
- **Authorization:** `Bearer Token`
- **Token:** `ExampleToken`
- **Body:**

```json
{
  "model": "gpt-4.1-mini",
  "messages": [
    {
      "role": "user",
      "content": "Categorize this query: '{{session.message.text}}'"
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "query_categorization",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "The original user query"
          },
          "category": {
            "type": "string",
            "enum": ["billing", "support", "general"],
            "description": "The most appropriate category"
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Confidence score for the categorization"
          }
        },
        "required": ["query", "category", "confidence"],
        "additionalProperties": false
      }
    }
  }
}
```

The response from OpenAI:

```json
{
    "id": "chatcmpl-RandomId",
    "object": "chat.completion",
    "created": 1748503764,
    "model": "gpt-4.1-mini-2025-04-14",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "{\"query\":\"I have an issue with my account, for some reason the payment is not going through.?\",\"category\":\"billing\",\"confidence\":0.95}",
                "refusal": null,
                "annotations": []
            },
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 112,
        "completion_tokens": 32,
        "total_tokens": 144,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "audio_tokens": 0
        },
        "completion_tokens_details": {
            "reasoning_tokens": 0,
            "audio_tokens": 0,
            "accepted_prediction_tokens": 0,
            "rejected_prediction_tokens": 0
        }
    },
    "service_tier": "default",
    "system_fingerprint": "fp_randomId"
}
```

Extract the content from the response message using the Cue **Set** node. I used `{{session.response.statusCode}}` \= `200` If statement for error management.

1. **Set** node to extract message content. `$.choices[0].message.content`

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-05-29-at-10.16.58.png)

2\. **Set** node to extract category from the content. `$.category`

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-05-29-at-10.19.12-1.png)

3\. Dynamically assigning to Team based on Category.

![](https://help.cuedesk.com/content/images/2026/10/Screenshot-2025-05-29-at-10.22.54.png)