# Get the generation details

GET https://services.leadconnectorhq.com/conversation-ai/generations

Retrieves detailed information about AI responses including the System Prompt, Conversation history, Knowledge base, website, FAQ chunks, and Rich Text chunks.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `conversation-ai.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `messageId` | string | Yes | Message Id |
| `source` | string | Yes | Source of the AI message - conversation or workflow |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/conversation-ai/generations": {
      "get": {
        "summary": "Get the generation details",
        "operationId": "getTheGenerationDetails",
        "description": "Retrieves detailed information about AI responses including the System Prompt, Conversation history, Knowledge base, website, FAQ chunks, and Rich Text chunks.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "messageId",
            "required": true,
            "in": "query",
            "description": "Message Id",
            "schema": {
              "example": "messageId123",
              "type": "string"
            }
          },
          {
            "name": "source",
            "required": true,
            "in": "query",
            "description": "Source of the AI message - conversation or workflow",
            "schema": {
              "example": "conversation",
              "enum": [
                "conversation",
                "workflow"
              ],
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FetchAIResponseDetailsResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "conversation-ai.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "FetchAIResponseDetailsResponseDTO": {
        "type": "object",
        "properties": {
          "prompt": {
            "type": "string",
            "description": "The complete prompt used for the AI response.",
            "example": "Personality:\nFriendly and professional,\n\nIntent:\nAssist customers with inquiries\n\nAdditional Information:\nHandle basic support queries"
          },
          "intent": {
            "type": "string",
            "description": "The intent/goal extracted from location prompt.",
            "example": "Assist customers with product inquiries and support"
          },
          "responseMessage": {
            "type": "string",
            "description": "The response message generated by the AI.",
            "example": "Hello! I understand you're interested in our products. How can I assist you today?"
          },
          "faqs": {
            "type": "array",
            "description": "FAQ chunks used in generating the response from fine-tuned data.",
            "example": [
              {
                "id": "chunk_123",
                "content": "Our return policy allows returns within 30 days of purchase.",
                "title": "Return Policy FAQ"
              }
            ]
          },
          "website": {
            "type": "array",
            "description": "Website content chunks used in generating the response.",
            "example": [
              {
                "id": "chunk_456",
                "content": "We offer free shipping on orders over $50.",
                "url": "https://example.com/shipping"
              }
            ]
          },
          "agentId": {
            "type": "string",
            "description": "ID of the employee/agent that generated the response.",
            "example": "emp_123"
          },
          "input": {
            "type": "string",
            "description": "The original input message that triggered this response.",
            "example": "What is your return policy?"
          },
          "actionLogs": {
            "type": "array",
            "description": "List of actions taken during this interaction.",
            "example": [
              {
                "contactUpdateAction": [
                  {
                    "fieldId": "field_123",
                    "value": "John Doe"
                  }
                ]
              }
            ]
          },
          "history": {
            "type": "array",
            "description": "Conversation history leading up to this response.",
            "example": [
              {
                "role": "user",
                "content": "Hi, I have a question about returns"
              },
              {
                "role": "assistant",
                "content": "I'll be happy to help you with information about our return policy."
              }
            ]
          },
          "mode": {
            "type": "string",
            "description": "Mode of operation during this interaction.",
            "example": "auto-pilot"
          }
        },
        "required": [
          "prompt",
          "responseMessage",
          "actionLogs",
          "history"
        ],
        "title": "FetchAIResponseDetailsResponseDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/conversation-ai/generations"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "messageId": "<MESSAGEID>",
    "source": "<SOURCE>"
}

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

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/conversation-ai/generations?messageId=<MESSAGEID>&source=<SOURCE>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
