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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# API Reference

Technical reference for Rox AI API endpoints.

## Base URL

```
https://Rox-Turbo-API.hf.space
```

---

## Endpoints

### POST /chat - Rox Core
### POST /turbo - Rox 2.1 Turbo
### POST /coder - Rox 3.5 Coder
### POST /turbo45 - Rox 4.5 Turbo
### POST /ultra - Rox 5 Ultra
### POST /dyno - Rox 6 Dyno
### POST /coder7 - Rox 7 Coder
### POST /vision - Rox Vision Max
### POST /hf/generate - HuggingFace Compatible

All endpoints use the same request/response format.

#### Request

**URL**: `/chat`  
**Method**: `POST`  
**Content-Type**: `application/json`

**Body Parameters**:

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `messages` | Array<Message> | Yes | - | Array of conversation messages |
| `temperature` | Float | No | 1.0 | Controls randomness (0.0 - 2.0) |
| `top_p` | Float | No | 1.0 | Nucleus sampling parameter (0.0 - 1.0) |
| `max_tokens` | Integer | No | 4096 | Maximum tokens in response |

**Message Object**:

```typescript
{
  role: "user" | "assistant",
  content: string
}
```

**Example Request**:

```json
{
  "messages": [
    {
      "role": "user",
      "content": "What is artificial intelligence?"
    }
  ],
  "temperature": 1.0,
  "top_p": 0.95,
  "max_tokens": 512
}
```

#### Response

**Success Response** (200 OK):

```json
{
  "content": "Artificial intelligence (AI) refers to..."
}
```

**Response Fields**:

| Field | Type | Description |
|-------|------|-------------|
| `content` | String | The generated response from Rox Core |

**Error Responses**:

**500 Internal Server Error**:
```json
{
  "detail": "Internal server error while calling Rox Core."
}
```

**502 Bad Gateway**:
```json
{
  "detail": "Bad response from upstream model provider."
}
```

**422 Unprocessable Entity**:
```json
{
  "detail": [
    {
      "loc": ["body", "messages"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

#### Example Usage

**cURL**:
```bash
curl -X POST https://Rox-Turbo-API.hf.space/chat \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Hello!"}
    ],
    "temperature": 1.0,
    "max_tokens": 512
  }'
```

**JavaScript**:
```javascript
const response = await fetch('https://Rox-Turbo-API.hf.space/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    messages: [{ role: 'user', content: 'Hello!' }],
    temperature: 1.0,
    max_tokens: 512
  })
});

const data = await response.json();
console.log(data.content);
```

**Python**:
```python
import requests

response = requests.post('https://Rox-Turbo-API.hf.space/chat', json={
    'messages': [{'role': 'user', 'content': 'Hello!'}],
    'temperature': 1.0,
    'max_tokens': 512
})

print(response.json()['content'])
```

---

### POST /hf/generate

Hugging Face compatible text generation endpoint for single-turn interactions.

#### Request

**URL**: `/hf/generate`  
**Method**: `POST`  
**Content-Type**: `application/json`

**Body Parameters**:

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `inputs` | String | Yes | - | The input text/prompt |
| `parameters` | Object | No | {} | Generation parameters |

**Parameters Object**:

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `temperature` | Float | No | 1.0 | Controls randomness (0.0 - 2.0) |
| `top_p` | Float | No | 0.95 | Nucleus sampling (0.0 - 1.0) |
| `max_new_tokens` | Integer | No | 8192 | Maximum tokens to generate |

**Example Request**:

```json
{
  "inputs": "Write a haiku about technology",
  "parameters": {
    "temperature": 0.7,
    "top_p": 0.95,
    "max_new_tokens": 256
  }
}
```

#### Response

**Success Response** (200 OK):

```json
[
  {
    "generated_text": "Silicon dreams awake\nCircuits pulse with electric life\nFuture in our hands"
  }
]
```

**Response Format**:

Returns an array with a single object containing the generated text.

| Field | Type | Description |
|-------|------|-------------|
| `generated_text` | String | The generated response |

**Error Responses**:

Same as `/chat` endpoint (500, 502, 422).

#### Example Usage

**cURL**:
```bash
curl -X POST https://Rox-Turbo-API.hf.space/hf/generate \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": "Explain quantum computing",
    "parameters": {
      "temperature": 0.7,
      "max_new_tokens": 256
    }
  }'
```

**JavaScript**:
```javascript
const response = await fetch('https://Rox-Turbo-API.hf.space/hf/generate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    inputs: 'Explain quantum computing',
    parameters: {
      temperature: 0.7,
      max_new_tokens: 256
    }
  })
});

const data = await response.json();
console.log(data[0].generated_text);
```

**Python**:
```python
import requests

response = requests.post('https://Rox-Turbo-API.hf.space/hf/generate', json={
    'inputs': 'Explain quantum computing',
    'parameters': {
        'temperature': 0.7,
        'max_new_tokens': 256
    }
})

print(response.json()[0]['generated_text'])
```

---

## Parameters

### temperature

Controls output randomness.

- **Range**: 0.0 to 2.0
- **Default**: 1.0
- **Lower** (0.1-0.5): Focused, deterministic
- **Medium** (0.6-1.0): Balanced
- **Higher** (1.1-2.0): Creative, varied

Examples:
- `0.3`: Math problems, factual questions, code generation
- `0.7`: General conversation, explanations
- `1.2`: Creative writing, brainstorming, storytelling

**Example**:
```json
{
  "messages": [{"role": "user", "content": "What is 2+2?"}],
  "temperature": 0.2
}
```

### top_p

Nucleus sampling parameter.

- **Range**: 0.0 to 1.0
- **Default**: 0.95 (/hf/generate), 1.0 (/chat)
- **Lower**: More focused
- **Higher**: More diverse

Example:
```json
{
  "messages": [{"role": "user", "content": "Tell me a story"}],
  "top_p": 0.9
}
```

### max_tokens / max_new_tokens

Maximum tokens in response.

- **Range**: 1 to 8192
- **Default**: 4096 (/chat), 8192 (/hf/generate)

Token estimation:
- ~1 token ≈ 4 characters
- ~1 token ≈ 0.75 words

Example:

```json
{
  "messages": [{"role": "user", "content": "Brief summary of AI"}],
  "max_tokens": 150
}
```

---

## Error Handling

### Status Codes

| Code | Meaning | Description |
|------|---------|-------------|
| 200 | OK | Request successful |
| 422 | Unprocessable Entity | Invalid request format |
| 500 | Internal Server Error | Server-side error |
| 502 | Bad Gateway | Upstream model error |

### Error Response Format

```json
{
  "detail": "Error message here"
}
```

### Common Errors

Missing field:
```json
{
  "detail": [
    {
      "loc": ["body", "messages"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

Invalid type:
```json
{
  "detail": [
    {
      "loc": ["body", "temperature"],
      "msg": "value is not a valid float",
      "type": "type_error.float"
    }
  ]
}
```

Example error handler:

```javascript
async function safeRequest(endpoint, body) {
  try {
    const response = await fetch(endpoint, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(body)
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.detail || `HTTP ${response.status}`);
    }

    return await response.json();
  } catch (error) {
    console.error('API Error:', error);
    throw error;
  }
}
```

---

## Rate Limiting

No enforced rate limits. Implement client-side limiting as needed.

---

## Client Wrapper Example

```javascript
class RoxAI {
  constructor(baseURL = 'https://Rox-Turbo-API.hf.space') {
    this.baseURL = baseURL;
  }

  async chat(messages, options = {}) {
    const response = await fetch(`${this.baseURL}/chat`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        messages,
        temperature: options.temperature || 1.0,
        top_p: options.top_p || 0.95,
        max_tokens: options.max_tokens || 512
      })
    });

    if (!response.ok) {
      throw new Error(`HTTP ${response.status}`);
    }

    const data = await response.json();
    return data.content;
  }

  async generate(text, options = {}) {
    const response = await fetch(`${this.baseURL}/hf/generate`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        inputs: text,
        parameters: options
      })
    });

    if (!response.ok) {
      throw new Error(`HTTP ${response.status}`);
    }

    const data = await response.json();
    return data[0].generated_text;
  }
}

// Usage
const rox = new RoxAI();
const response = await rox.chat([
  { role: 'user', content: 'Hello!' }
]);
```

---

---

Built by Mohammad Faiz