# post\_\_conversation

{% hint style="info" %}
This API endpoint is currently available only in the TEST environment. It is not yet available in production.
{% endhint %}

`POST /conversation`

*Create Conversation*

Create a new AI conversation associated with a repository. Conversations are the context containers for AI interactions, allowing users to have multi-turn conversations with AI models through the Flashback platform.

**Key Features:**

* Creates a new conversation context for AI interactions
* Associates conversation with a specific repository
* Automatically inherits workspace and organization from the repository
* Tracks conversation metadata and token usage
* System events are logged for audit purposes

**Important Notes:**

* Users must have access to the repository's workspace to create conversations
* The repository must belong to a workspace (cannot be orphaned)
* Each conversation is tied to a single repository
* Conversations are soft-deleted (marked as deleted but not physically removed)

**Security:**

* Access is validated against workspace permissions
* Only users with workspace read access can create conversations
* Conversation creation triggers system events for audit trails

#### TypeScript Client Library

```typescript
public createConversation = async (data: CreateConversationRequest): Promise<CreateConversationResponse> => {
  return this.makeRequest<CreateConversationResponse>('conversation', 'POST', data);
};
```

#### Code Samples

{% tabs %}
{% tab title="Shell" %}

```shell
# You can also use wget
curl -X POST https://backend.flashback.tech/conversation \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
```

{% endtab %}

{% tab title="HTTP" %}

```http
POST https://backend.flashback.tech/conversation HTTP/1.1
Host: backend.flashback.tech
Content-Type: application/json
Accept: application/json
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const inputBody = '{
  "repoId": "repo-123"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('https://backend.flashback.tech/conversation',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.post 'https://backend.flashback.tech/conversation',
  params: {
  }, headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.post('https://backend.flashback.tech/conversation', headers = headers)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','https://backend.flashback.tech/conversation', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
```

{% endtab %}

{% tab title="Java" %}

```java
URL obj = new URL("https://backend.flashback.tech/conversation");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "https://backend.flashback.tech/conversation", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}
```

{% endtab %}
{% endtabs %}

> Body parameter

```json
{
  "repoId": "repo-123"
}
```

#### Parameters <a href="#post__conversation-parameters" id="post__conversation-parameters"></a>

| Name     | In   | Type   | Required | Description                         |
| -------- | ---- | ------ | -------- | ----------------------------------- |
| body     | body | object | true     | none                                |
| » repoId | body | string | true     | Unique identifier of the repository |

> Example responses

> 200 Response

```json
{
  "success": true,
  "conversationId": "550e8400-e29b-41d4-a716-446655440000"
}
```

#### Responses <a href="#post__conversation-responses" id="post__conversation-responses"></a>

| Status | Meaning                                                                    | Description                       | Schema |
| ------ | -------------------------------------------------------------------------- | --------------------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)                    | Conversation created successfully | Inline |
| 400    | [Bad Request](https://tools.ietf.org/html/rfc7231#section-6.5.1)           | Validation error or invalid input | Inline |
| 403    | [Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3)             | Insufficient permissions          | Inline |
| 404    | [Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4)             | Repository not found              | Inline |
| 500    | [Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) | Failed to create conversation     | Inline |

#### Response Schema <a href="#post__conversation-responseschema" id="post__conversation-responseschema"></a>

Status Code **200**

| Name             | Type    | Required | Restrictions | Description                                    |
| ---------------- | ------- | -------- | ------------ | ---------------------------------------------- |
| » success        | boolean | false    | none         | Operation success status                       |
| » conversationId | string  | false    | none         | Unique identifier for the created conversation |

Status Code **400**

| Name      | Type    | Required | Restrictions | Description   |
| --------- | ------- | -------- | ------------ | ------------- |
| » success | boolean | false    | none         | none          |
| » message | string  | false    | none         | Error message |

Status Code **403**

| Name      | Type    | Required | Restrictions | Description   |
| --------- | ------- | -------- | ------------ | ------------- |
| » success | boolean | false    | none         | none          |
| » message | string  | false    | none         | Error message |

Status Code **404**

| Name      | Type    | Required | Restrictions | Description   |
| --------- | ------- | -------- | ------------ | ------------- |
| » success | boolean | false    | none         | none          |
| » message | string  | false    | none         | Error message |

Status Code **500**

| Name      | Type    | Required | Restrictions | Description   |
| --------- | ------- | -------- | ------------ | ------------- |
| » success | boolean | false    | none         | none          |
| » message | string  | false    | none         | Error message |

To perform this operation, you must be authenticated by means of one of the following methods: BearerAuth
