> For the complete documentation index, see [llms.txt](https://team-jai-jts.gitbook.io/en-jts-ai-studio/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://team-jai-jts.gitbook.io/en-jts-ai-studio/detail/using-jts-ai-studio/service-openapi.md).

# Service OpenAPI

You can utilize OpenAPI to integrate deployed models into live services. Both the Conversation API and Embedding API are available, and API keys can be issued through the group manager.

Refer to the [client management page](https://1700523543-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces/cNHSxAOna3NeMSyiBFBX/uploads/3S2XQny6QisPHHG4nHA6/undefined%25205?alt=media) for API key issuance.

{% hint style="info" %}

* The Dialogue API enables interactive Q\&A functionality with the model.&#x20;
* Embedding API Generates a vector representation for a given sentence.
  {% endhint %}

### Using the Conversation API <a href="#api" id="api"></a>

**\<Basic Information>**

<table><thead><tr><th width="109">Method</th><th>URL</th></tr></thead><tbody><tr><td>POST</td><td>https://jai.jts.co.th/v1/chat/completions</td></tr></tbody></table>

Request Example

***

```
curl -X POST 'https://jai.jts.co.th/v1/chat/completions' \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Authorization: Bearer kai-XXXXXXXdGVzdC1zZWNyZXQ=' \
-d  '{
    "model": "deployId",
    "messages": [
      {
        "role": "user",
        "content": "hello"
      }
    ],
    "temperature": 0.5,
    "stream": false
}'
```

* The API body must be provided in JSON format.
* To verify client authenticity, include the issued token in the request header.&#x20;
* Enter the ID of the deployed service from the studio in the "model" attribute.
* Use "messages" to input a list of messages that make up the current conversation, with each message containing "role" (indicating the speaker) and "content" (the actual message text).
* Set inference parameters using the fields below.

  ※ For available parameters, please refer to the API specification table below.
* If these inference parameters are not specified, the default values defined at deployment will apply.
* The "stream" attribute determines whether to enable stream mode. If stream mode is disabled, the response will be delivered in full once completed. When enabled, responses are streamed via SSE (Server-Sent-Event) as each character is generated. If "stream" is not specified, it defaults to false.

Response Example

***

```
{
   "id":"66d02a1f8675b795b38241002524171c",
   "object":"text_completion",
   "created":1724918313,
   "model":"deployId",
   "choices":[
      {
         "index":0,
         "text":"Hi there! How can I assist you today?",
         "logprobs":null,
         "finish_reason":"stop"
      }
   ],
   "usage":{
      "prompt_tokens":4,
      "completion_tokens":10,
      "total_tokens":14
   }
}
```

#### API Specification <a href="#api-1" id="api-1"></a>

**\<Request Body>**

<table><thead><tr><th width="197">Name</th><th width="193">Type</th><th width="222">Description</th><th>Required</th></tr></thead><tbody><tr><td>model</td><td>String</td><td>Deployment ID</td><td>O</td></tr><tr><td>messages</td><td>List</td><td>List of request messages (previous conversation history + new message)</td><td>O</td></tr><tr><td>-role</td><td>String</td><td><p>Message initiator, options include "user"</p><p>"assistant (service)," and "system"</p></td><td>O</td></tr><tr><td>-content</td><td>String</td><td>Message content</td><td>O</td></tr><tr><td>logit_bias</td><td>Map&#x3C;String, Integer></td><td>Logit bias</td><td>X</td></tr><tr><td>max_tokens</td><td>Integer</td><td>Maximum number of tokens</td><td>X</td></tr><tr><td>temperature</td><td>Double</td><td>Controls exploration range and diversity</td><td>X</td></tr><tr><td>presence_penalty</td><td>Double</td><td>Presence penalty</td><td>X</td></tr><tr><td>top_p</td><td>Double</td><td>Cumulative probability sampling</td><td>X</td></tr><tr><td>stream</td><td>Boolean</td><td>Option to use stream mode (default: false)</td><td>X</td></tr><tr><td>logprobs</td><td>Boolean</td><td>Log probability</td><td>X</td></tr><tr><td>top_logprobs</td><td>Integer</td><td>Top Log probability</td><td>X</td></tr><tr><td>stop</td><td>String/List</td><td>Stop condition</td><td>X</td></tr><tr><td>seed</td><td>Integer</td><td>Seed</td><td>X</td></tr><tr><td>response_format</td><td>Object</td><td>Response format</td><td>X</td></tr></tbody></table>

**\<Response>**

| Name                | Type    | Description                                              |
| ------------------- | ------- | -------------------------------------------------------- |
| id                  | String  | Transaction ID                                           |
| object              | String  | Internal system sequence                                 |
| created             | Long    | Creation date and time                                   |
| model               | String  | Deployment ID                                            |
| choices             | List    | Selection list                                           |
| -index              | String  | Index                                                    |
| -message            | Object  | Response message object                                  |
| .role               | String  | Message initiator                                        |
| .content            | String  | Message content                                          |
| -finish\_reason     | String  | Reason for completion                                    |
| -logprobs           | String  | Option to return log probabilities for each output token |
| usage               | Object  | Usage statistics                                         |
| -prompt\_tokens     | Integer | Number of prompt tokens used                             |
| -completion\_tokens | Integer | Number of completion tokens used                         |
| -total\_tokens      | Integer | Total token count                                        |

### Using the Embedding API <a href="#api-2" id="api-2"></a>

**\<Basic Information>**

| Method | URL                                   |
| ------ | ------------------------------------- |
| POST   | <https://jai.jts.co.th/v1/embeddings> |

Request Example

***

```
curl --location 'https://jai.jts.co.th/v1/embeddings' \
--header 'Authorization: Bearer kai-XXXXXXXdGVzdC1zZWNyZXQ=' \
--header 'Content-Type: application/json' \
--data '{
    "input": "The food was delicious and the waiter...",
    "model": "base-solar-embedding-v1_D1"
}'
```

* The API body must be provided in JSON format.
* To verify client authenticity, include the issued token in the request header.
* Enter the ID of the deployed service from the studio in the "model" attribute.

Response Example

***

```
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        ...
        -0.0028842222,
      ],
      "index": 0
    }
  ],
  "model": "base-solar-embedding-v1_D1",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
```

#### **API** Specification <a href="#api-3" id="api-3"></a>

**\<Request Body>**

| Name             | Type   | Description     | Required |
| ---------------- | ------ | --------------- | -------- |
| model            | String | Deployment ID   | O        |
| input            | String | User input text | O        |
| encoding\_format | String | Encoding format | X        |

**\<Response>**

| Name       | Type          | Description               |
| ---------- | ------------- | ------------------------- |
| model      | String        | Deployment ID             |
| data       | List\<Object> | Response data             |
| -embedding | List          | List of generated vectors |
| usage      | Object        | Number of tokens used     |

### Embedding Models

**\<Available model>**

<table><thead><tr><th width="266">Model</th><th width="181">Context length</th><th>Description</th></tr></thead><tbody><tr><td>embedding-query<br><em>(Prev. jts-embedding-1-large-query)</em></td><td>4,000</td><td>JAI LLM-based Passage Embedding model with a 4k context limit. This model is optimized for embedding documents or texts to be searched.</td></tr><tr><td>embedding-passage<br><em>(Prev. jts-embedding-1-large-passage)</em></td><td>4,000</td><td>JAI LLM-based Query Embedding model with a 4k context limit. This model is optimized for embedding user's question in information-seeking tasks such as retrieval &#x26; reranking.</td></tr></tbody></table>

**\<What is the difference between passage and query models?>**

* Passage and query refer to different types of text. Both are converted into vectors to calculate similarity, but they serve different roles:
* Passage: Typically represents a portion of a document, a sentence, or longer text. It refers to a specific section or fragment of the text, often containing information. For example, a paragraph from a research paper or a description on a webpage can be used as a passage. In LLM Embeddings, this passage is converted into a vector.
* Query: This is a question or search term that the user inputs to find information. It's usually shorter and more specific compared to a passage, conveying the user's intent to retrieve certain information. The query is also converted into a vector, and its similarity to the passage vectors is measured.
