# Chat with Endpoint

## From Chat Playground

When your inference instance turns active, a button "Open Playground" will appear if the model hosted is Open AI compatible.

Click the button to access Chat Playground! You'll be able to interact with your endpoint, and change parameters such as Temperature, Top-p, Top-k and repetition penalty.

<figure><img src="https://3376774032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoExYATuECEyEKGJ4cD8X%2Fuploads%2FLu1cwPAe94toMQ41odoE%2FScreenshot%202025-03-13%20at%2014.23.16.png?alt=media&#x26;token=c861ccdf-1ea1-46b0-9dff-60e8f3f1cf85" alt=""><figcaption></figcaption></figure>

## From your Terminal

To interact with the endpoint directly from your terminal, you'll need to follow this process. Our endpoints follow OpenAI's specification, enabling seamless integration with existing tools and libraries.

### Prerequisites

* Your endpoint URL (format: `https://<id>-<hash>.ai.sesterce.dev/`)
* Your API Secret (provided upon deployment)
* Model ID (retrieved via API)
* OpenAI-compatible client or SDK

### Authentication

#### Verifying connection

First, list available models:

```
curl -H "x-api-key: <SECRET>" -X GET "<ENDPOINT>/v1/models"
```

### Model types and endpoints

{% hint style="info" %}
Ensure to replace \<SECRET> by your own secret (available from launched instance page), as well as \<MODEL\_ID> and \<ENDPOINT>, to be replaced by your own data.
{% endhint %}

#### 1. Text generation

Endpoint: `/v1/chat/completions`

```
curl -H "Content-Type: application/json" \
     -H "x-api-key: <SECRET>" \
     -X POST "<ENDPOINT>/v1/chat/completions" \
     -d '{
       "model": "<MODEL_ID>",
       "messages": [
         {
           "role": "user",
           "content": "Hello, how are you?"
         }
       ]
     }'
```

#### 2. Multimodel (text+image)

Endpoint: `/v1/chat/completions`

```
curl -H "Content-Type: application/json" \
     -H "x-api-key: <SECRET>" \
     -X POST "<ENDPOINT>/v1/chat/completions" \
     -d '{
       "model": "<MODEL_ID>",
       "messages": [
         {
           "role": "user",
           "content": [
             {
               "type": "text",
               "text": "What's in this image?"
             },
             {
               "type": "image_url",
               "image_url": {
                 "url": "https://example.com/image.jpg"
               }
             }
           ]
         }
       ]
     }'
```

#### 3. Audio-Speech Recognition (ASR)

Endpoint: `/v1/audio/transcriptions`

```
curl -H "x-api-key: <SECRET>" \
     -X POST "<ENDPOINT>/v1/audio/transcriptions" \
     -H "Content-Type: multipart/form-data" \
     -F file="@/path/to/audio.mp3" \
     -F model="<MODEL_ID>"
```

### Open AI SDK integration

#### Javascript/Typescript

```javascript
import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: "<SECRET>",
    baseURL: "<ENDPOINT>/v1"
});

// Text Generation
async function generateText() {
    const completion = await openai.chat.completions.create({
        model: "<MODEL_ID>",
        messages: [
            {
                role: "user",
                content: "Hello, how are you?"
            }
        ]
    });
    console.log(completion.choices[0].message.content);
}

// Multimodal
async function analyzeImage() {
    const response = await openai.chat.completions.create({
        model: "<MODEL_ID>",
        messages: [
            {
                role: "user",
                content: [
                    {
                        type: "text",
                        text: "What's in this image?"
                    },
                    {
                        type: "image_url",
                        image_url: {
                            url: "https://example.com/image.jpg"
                        }
                    }
                ]
            }
        ]
    });
}
```

#### Python

```python
from openai import OpenAI

client = OpenAI(
    api_key="<SECRET>",
    base_url="<ENDPOINT>/v1"
)

# Text Generation
response = client.chat.completions.create(
    model="<MODEL_ID>",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

# Audio Transcription
with open("audio.mp3", "rb") as audio_file:
    transcript = client.audio.transcriptions.create(
        model="<MODEL_ID>", 
        file=audio_file
    )
```

### Best Practices

1. **Performance Optimization**
   * Use batch processing for multiple requests
   * Implement caching when possible
   * Compress files before upload
   * Use URLs for large files
2. **Security**
   * Never share your API Secret
   * Implement rate limiting
   * Monitor usage patterns
   * Secure stored credentials
3. **Integration Tips**
   * Always validate model availability
   * Implement proper error handling
   * Use the SDK for robust integration
   * Keep dependencies updated

### Supported Formats and Limitations

#### File Formats

* Images: JPEG, PNG, WEBP, GIF
* Audio: mp3, mp4, mpeg, mpga, m4a, wav, webm

#### Size Limits

* Images: Maximum 20MB
* Audio: Maximum 25MB
* Audio Duration: Up to 4 hours

### Error Handling

#### Common Error Codes

* 401: Invalid API Secret
* 404: Model not found
* 429: Too many requests
* 500: Server error

#### Error Handling example

```
try:
    response = client.chat.completions.create(...)
except Exception as e:
    if "file too large" in str(e):
        # Handle size error
    elif "unsupported file type" in str(e):
        # Handle format error
    else:
        # Handle other errors
```

If you need support, please reach us at <support@sesterce.com>.
