# Generating response using Quack AI

### Authentication <a href="#authentication" id="authentication"></a>

Authenticating to the API is done using an API key that is passed in an Authentication header. All requests to an API endpoint, must contain the following header:

```
Authorization: Bearer <API_KEY>
```

To get your `API_KEY` reach out to your account manager @Quack AI.

### POST /conversation

Start a conversation. Optionally, send context data to initialize the session. A `conversation_id` will be returned in the response header.

**Request:**

```json
// Headers
"X-Quack-Conversation-ID": "abc123" // if you don't have send without -> it will create a new one
```

```json
// Payload example
{
  "context": {
    "user_id": "1234",
    "product_line": "Product 1"
  },
  "messages":[
  // you can put here previous messages
    {
      "content":"what integrations you support? ",
      "role":"user" // roles will always be user or assistant
    },
  ]
}
```

```typescript
// ץא
// conversation.types.ts

type Message {
    content:string;
    role: "user" | "assistant"
}

interface ConversationRequestParams {
    context?:any,
    messages:Message[]
}
```

{% hint style="info" %}
For not streamed response - add query param⇒ \`stream=false\`
{% endhint %}

**Response ( will be streamed ):**

```http
200 Created
X-Quack-Conversation-ID: "abc123"
Content-Type: "text/plain; charset=utf-8" // It will be streamed back
```

#### In case of answer:

````
```
0:"Hi"
0:","
0:" This"
0:" Will"
0:" be"
0:" the response"
0:".\n\n"
0:"Quack"
0:" will"
0:" stream"
0:" it"
```
````

#### In case of escalating to agent &#x20;

````
// the response will include toolCallId with result of "talk_to_an_agent"
```
a:{"toolCallId":"call_P9Xonb8qLaqwAursPMOHzibE","result":"talk_to_an_agent"}
```
````

#### In case of skipping ( out of scope for Quack / Quack can't answer it ):&#x20;

````
// the response will include toolCallId with result of "skip_it"
```
a:{"toolCallId":"call_orLGhq3LG9tKkCOErl3DJJoW","result":"skip_it"}
```
````


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://integrations.quack.ai/BKUZmzGN2Mmipf4UROTF/api/generating-response-using-quack-ai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
