# Nova AI Chat Completion

The Nova AI Chat Completion API lets you generate text responses from Nova AI models using the OpenAI-compatible chat format. Send a conversation of messages and receive an AI-generated reply.

> [!IMPORTANT]
> **Powered by Nova AI**
> This endpoint proxies requests to Nova AI's chat completions service. This endpoint counts toward your **AI request limit**.
>
> For available models and their capabilities, see: [Nova AI Model Docs](https://nova-ai.nabzclan.vip/user/developer/docs/models)

## Endpoint

**POST** `https://developer.nabzclan.vip/api/v1/novaai/chat/completions`

## Authentication

Include your API key in the `Authorization` header:

```bash
Authorization: Bearer YOUR_API_TOKEN
```

## Request Parameters

### Required
- **model** (string): The model ID to use (e.g. `nova_1_1`). See [available models](https://nova-ai.nabzclan.vip/user/developer/docs/models).
- **messages** (array): An array of message objects with `role` and `content`.
  - **role** (string): One of `system`, `user`, or `assistant`.
  - **content** (string): The message text.

### Optional
- **temperature** (number): Sampling temperature between 0 and 2. Higher values make output more random. Default varies by model.
- **max_tokens** (integer): Maximum number of tokens to generate. Max 128,000.
- **stream** (boolean): If `true`, responses are streamed as Server-Sent Events (SSE).

## Response Format

```json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1711000000,
  "model": "nova_1_1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Lines of logic flow,\nBugs hide in the syntax tree,\nCoffee fuels the fix."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 24,
    "total_tokens": 36
  }
}
```

## Rate Limiting

This endpoint uses **AI request limits** based on your plan:

| Plan   | AI Requests | Period  |
|--------|-------------|---------|
| Free   | 10          | Per day |
| VIP 1  | 100         | Per day |
| VIP 2  | 500         | Per day |
| VIP 3  | 2,000       | Per day |
| VIP 4  | 10,000      | Per day |

## Examples

### 1. Basic Chat

```bash
curl -X POST https://developer.nabzclan.vip/api/v1/novaai/chat/completions \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "nova_1_1",
    "messages": [
      {
        "role": "user",
        "content": "Write a haiku about programming"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 100
  }'
```

### 2. With System Prompt

```bash
curl -X POST https://developer.nabzclan.vip/api/v1/novaai/chat/completions \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "nova_1_1",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful coding assistant."
      },
      {
        "role": "user",
        "content": "How do I reverse a string in Python?"
      }
    ]
  }'
```

### 3. Multi-turn Conversation

```bash
curl -X POST https://developer.nabzclan.vip/api/v1/novaai/chat/completions \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "nova_1_1",
    "messages": [
      {"role": "user", "content": "What is recursion?"},
      {"role": "assistant", "content": "Recursion is when a function calls itself to solve a problem by breaking it into smaller subproblems."},
      {"role": "user", "content": "Give me an example in JavaScript"}
    ],
    "temperature": 0.5
  }'
```

### 4. Python Example

```python
import requests

url = "https://developer.nabzclan.vip/api/v1/novaai/chat/completions"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
data = {
    "model": "nova_1_1",
    "messages": [
        {"role": "user", "content": "Explain APIs in one sentence"}
    ],
    "max_tokens": 50
}

response = requests.post(url, headers=headers, json=data)
print(response.json()["choices"][0]["message"]["content"])
```

### 5. Streaming (Python)

```python
import requests

url = "https://developer.nabzclan.vip/api/v1/novaai/chat/completions"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
data = {
    "model": "nova_1_1",
    "messages": [{"role": "user", "content": "Tell me a short story"}],
    "stream": True
}

response = requests.post(url, headers=headers, json=data, stream=True)
for line in response.iter_lines():
    if line:
        print(line.decode("utf-8"))
```
