Blame

445f4f admin 2024-08-22 15:52:53 1
# chatapi.ai-now.space API Documentation
2
543776 admin 2024-08-24 09:47:16 3
This document provides a comprehensive overview of the chatapi.ai-now.space API, detailing its functionalities, endpoints, and usage instructions.
4
5
## Overview
6
7
chatapi.ai-now.space is a proxy API that provides access to various large language models (LLMs) for chat completions and other AI-related tasks. It offers a unified interface for interacting with different models, simplifying the development process for users.
445f4f admin 2024-08-22 15:52:53 8
9
## Authentication
10
543776 admin 2024-08-24 09:47:16 11
All API requests require an API key for authentication. To obtain an API key, please contact [email protected].
445f4f admin 2024-08-22 15:52:53 12
543776 admin 2024-08-24 09:47:16 13
The API key should be included in the `Authorization` header of each request using the `Bearer` scheme:
445f4f admin 2024-08-22 15:52:53 14
15
```
16
Authorization: Bearer YOUR_API_KEY
17
```
18
19
## Endpoints
20
543776 admin 2024-08-24 09:47:16 21
### `/models`
445f4f admin 2024-08-22 15:52:53 22
543776 admin 2024-08-24 09:47:16 23
**GET** - Retrieves a list of available models.
445f4f admin 2024-08-22 15:52:53 24
25
**Response:**
26
27
```json
28
{
29
"data": [
30
{
543776 admin 2024-08-24 09:47:16 31
"id": 1,
32
"name": "Model A",
33
"contextWindow": 2048,
34
"inputCostPer1kTokens": 0.001,
35
"outputCostPer1kTokens": 0.002,
36
"quality": "high",
37
"medianPrice": 0.05,
38
"outputTokensPerSecond": 10,
39
"latencyToFirstChunk": 500,
40
"average": 85,
41
"multiChoiceQs": 90,
42
"reasoning": 80,
43
"pythonCoding": 75,
44
"futureCapabilities": 70,
45
"gradeSchoolMath": 95,
46
"mathProblems": 80,
47
"arenaScore": 75,
48
"confidenceInterval": 90,
49
"votes": 100,
50
"organization": "Organization A",
51
"license": "MIT",
52
"knowledgeCutoff": "2023-01-01",
53
"working": true
445f4f admin 2024-08-22 15:52:53 54
},
55
// ... other models
56
]
57
}
58
```
48bd79 admin 2024-09-06 16:35:41 59
### [Full list of models is available here](https://chatapi.ai-now.space/listmodels)
445f4f admin 2024-08-22 15:52:53 60
543776 admin 2024-08-24 09:47:16 61
**Example:**
445f4f admin 2024-08-22 15:52:53 62
543776 admin 2024-08-24 09:47:16 63
```bash
64
curl -H "Authorization: Bearer YOUR_API_KEY" https://chatapi.ai-now.space/models
65
```
66
67
### `/chat/completions`
445f4f admin 2024-08-22 15:52:53 68
543776 admin 2024-08-24 09:47:16 69
**POST** - Generates chat completions using the specified model.
445f4f admin 2024-08-22 15:52:53 70
543776 admin 2024-08-24 09:47:16 71
**Request Body:**
445f4f admin 2024-08-22 15:52:53 72
73
```json
74
{
543776 admin 2024-08-24 09:47:16 75
"model": "Model A",
445f4f admin 2024-08-22 15:52:53 76
"messages": [
543776 admin 2024-08-24 09:47:16 77
{ "role": "user", "content": "What is the capital of France?" }
445f4f admin 2024-08-22 15:52:53 78
],
543776 admin 2024-08-24 09:47:16 79
"stream": false, // Optional, defaults to false
80
// ... other parameters (see OpenAI's Chat Completion API documentation)
445f4f admin 2024-08-22 15:52:53 81
}
82
```
83
543776 admin 2024-08-24 09:47:16 84
**Response (Non-Streaming):**
445f4f admin 2024-08-22 15:52:53 85
86
```json
87
{
543776 admin 2024-08-24 09:47:16 88
"id": "chatcmpl-XXXXXXXXXXXXXXXXX",
445f4f admin 2024-08-22 15:52:53 89
"object": "chat.completion",
543776 admin 2024-08-24 09:47:16 90
"created": 1678886384,
91
"model": "Model A",
445f4f admin 2024-08-22 15:52:53 92
"choices": [
93
{
94
"index": 0,
95
"message": {
96
"role": "assistant",
97
"content": "The capital of France is Paris."
98
},
99
"finish_reason": "stop"
100
}
101
],
543776 admin 2024-08-24 09:47:16 102
"input_tokens": 7,
103
"output_tokens": 6,
104
"input_tokens_cost": 0.000007,
105
"output_tokens_cost": 0.000012,
106
"total_tokens_cost": 0.000019,
107
"total_time_taken": 123,
108
"tokens_per_second": 0.1057
445f4f admin 2024-08-22 15:52:53 109
}
110
```
111
543776 admin 2024-08-24 09:47:16 112
**Response (Streaming):**
445f4f admin 2024-08-22 15:52:53 113
114
```text
543776 admin 2024-08-24 09:47:16 115
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {"content": "The"}, "finish_reason": null}]}
116
117
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {"content": " capital"}, "finish_reason": null}]}
118
119
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {"content": " of"}, "finish_reason": null}]}
120
121
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {"content": " France"}, "finish_reason": null}]}
445f4f admin 2024-08-22 15:52:53 122
543776 admin 2024-08-24 09:47:16 123
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {"content": " is"}, "finish_reason": null}]}
445f4f admin 2024-08-22 15:52:53 124
543776 admin 2024-08-24 09:47:16 125
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {"content": " Paris."}, "finish_reason": null}]}
445f4f admin 2024-08-22 15:52:53 126
543776 admin 2024-08-24 09:47:16 127
data: {"id": "chatcmpl-XXXXXXXXXXXXXXXXX", "object": "chat.completion.chunk", "created": 1678886384, "model": "Model A", "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]}
445f4f admin 2024-08-22 15:52:53 128
543776 admin 2024-08-24 09:47:16 129
data: {"input_tokens": 7, "output_tokens": 6, "input_tokens_cost": 0.000007, "output_tokens_cost": 0.000012, "total_tokens_cost": 0.000019, "total_time_taken": 123, "tokens_per_second": 0.1057}
445f4f admin 2024-08-22 15:52:53 130
543776 admin 2024-08-24 09:47:16 131
data: [DONE]
132
```
133
134
**Example (Non-Streaming):**
135
136
```bash
137
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
138
"model": "Model A",
139
"messages": [
140
{ "role": "user", "content": "What is the capital of France?" }
141
]
142
}' https://chatapi.ai-now.space/chat/completions
445f4f admin 2024-08-22 15:52:53 143
```
144
543776 admin 2024-08-24 09:47:16 145
**Example (Streaming):**
146
147
```bash
148
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
149
"model": "Model A",
150
"messages": [
151
{ "role": "user", "content": "What is the capital of France?" }
152
],
153
"stream": true
154
}' https://chatapi.ai-now.space/chat/completions
155
```
445f4f admin 2024-08-22 15:52:53 156
543776 admin 2024-08-24 09:47:16 157
### `/tokens`
445f4f admin 2024-08-22 15:52:53 158
543776 admin 2024-08-24 09:47:16 159
**POST** - Counts the number of tokens in a given text.
445f4f admin 2024-08-22 15:52:53 160
161
**Request Body:**
162
163
```json
164
{
543776 admin 2024-08-24 09:47:16 165
"text": "This is a test sentence."
445f4f admin 2024-08-22 15:52:53 166
}
167
```
168
169
**Response:**
170
171
```json
172
{
543776 admin 2024-08-24 09:47:16 173
"tokens": 6
445f4f admin 2024-08-22 15:52:53 174
}
175
```
176
543776 admin 2024-08-24 09:47:16 177
**Example:**
445f4f admin 2024-08-22 15:52:53 178
543776 admin 2024-08-24 09:47:16 179
```bash
180
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
181
"text": "This is a test sentence."
182
}' https://chatapi.ai-now.space/tokens
183
```
184
185
### `/credits`
445f4f admin 2024-08-22 15:52:53 186
543776 admin 2024-08-24 09:47:16 187
**GET** - Retrieves the remaining credits for the API key.
445f4f admin 2024-08-22 15:52:53 188
189
**Response:**
190
191
```json
192
{
193
"credits": 1000
194
}
195
```
196
543776 admin 2024-08-24 09:47:16 197
**Example:**
445f4f admin 2024-08-22 15:52:53 198
543776 admin 2024-08-24 09:47:16 199
```bash
200
curl -H "Authorization: Bearer YOUR_API_KEY" https://chatapi.ai-now.space/credits
201
```
445f4f admin 2024-08-22 15:52:53 202
543776 admin 2024-08-24 09:47:16 203
### `/moderate`
204
205
**POST** - Moderates the given input text using OpenAI's moderation API.
445f4f admin 2024-08-22 15:52:53 206
207
**Request Body:**
208
209
```json
210
{
543776 admin 2024-08-24 09:47:16 211
"input": "This is a test sentence."
445f4f admin 2024-08-22 15:52:53 212
}
213
```
214
215
**Response:**
216
217
```json
218
{
543776 admin 2024-08-24 09:47:16 219
"id": "modr-XXXXXXXXXXXXXXXXX",
220
"model": "text-moderation-latest",
445f4f admin 2024-08-22 15:52:53 221
"results": [
222
{
223
"categories": {
224
"hate": false,
225
"hate/threatening": false,
543776 admin 2024-08-24 09:47:16 226
"self-harm": false,
227
"sexual": false,
228
"sexual/minors": false,
229
"violence": false,
230
"violence/graphic": false
445f4f admin 2024-08-22 15:52:53 231
},
232
"category_scores": {
233
"hate": 0.0000000000000000,
234
"hate/threatening": 0.0000000000000000,
543776 admin 2024-08-24 09:47:16 235
"self-harm": 0.0000000000000000,
236
"sexual": 0.0000000000000000,
237
"sexual/minors": 0.0000000000000000,
238
"violence": 0.0000000000000000,
239
"violence/graphic": 0.0000000000000000
445f4f admin 2024-08-22 15:52:53 240
},
241
"flagged": false
242
}
243
]
244
}
245
```
246
543776 admin 2024-08-24 09:47:16 247
**Example:**
248
249
```bash
250
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
251
"input": "This is a test sentence."
252
}' https://chatapi.ai-now.space/moderate
253
```
254
255
## Rate Limiting
256
257
The API is rate limited to 100 requests per minute per API key. Exceeding this limit will result in a `429 Too Many Requests` error.
258
259
## Error Handling
260
261
The API uses standard HTTP status codes to indicate the success or failure of a request. Common error codes include:
262
263
* **400 Bad Request:** The request was malformed or invalid.
264
* **401 Unauthorized:** The API key was missing or invalid.
265
* **429 Too Many Requests:** The rate limit has been exceeded.
266
* **500 Internal Server Error:** An unexpected error occurred on the server.
267
268
## Contact
269
270
For any questions or issues, please contact [email protected].
271
445f4f admin 2024-08-22 15:52:53 272
273
cdc885 admin 2024-08-22 16:03:54 274
## Usage Examples
275
276
### Python
445f4f admin 2024-08-22 15:52:53 277
cdc885 admin 2024-08-22 16:03:54 278
#### Non-Streaming Example
445f4f admin 2024-08-22 15:52:53 279
280
```python
281
import requests
282
283
headers = {
284
'Authorization': 'Bearer YOUR_API_KEY',
285
'Content-Type': 'application/json'
286
}
287
288
data = {
289
'model': 'GPT-4 Turbo',
290
'messages': [
291
{'role': 'system', 'content': 'You are a helpful assistant.'},
292
{'role': 'user', 'content': 'What is the capital of France?'}
293
]
294
}
295
296
response = requests.post('https://chatapi.ai-now.space/chat/completions', headers=headers, json=data)
297
298
print(response.json())
299
```
300
cdc885 admin 2024-08-22 16:03:54 301
#### Streaming Example
445f4f admin 2024-08-22 15:52:53 302
303
```python
304
import requests
305
306
headers = {
307
'Authorization': 'Bearer YOUR_API_KEY',
308
'Content-Type': 'application/json'
309
}
310
311
data = {
312
'model': 'Claude 3.5 Sonnet',
313
'messages': [
314
{'role': 'system', 'content': 'You are a helpful assistant.'},
315
{'role': 'user', 'content': 'Write a short poem about the sea.'}
316
],
317
'stream': True
318
}
319
320
response = requests.post('https://chatapi.ai-now.space/chat/completions', headers=headers, json=data, stream=True)
321
322
for line in response.iter_lines():
323
if line:
324
decoded_line = line.decode('utf-8')
325
if decoded_line.startswith('data: '):
326
print(decoded_line[6:])
327
```
328
cdc885 admin 2024-08-22 16:03:54 329
### C#
445f4f admin 2024-08-22 15:52:53 330
cdc885 admin 2024-08-22 16:03:54 331
#### Non-Streaming Example
445f4f admin 2024-08-22 15:52:53 332
333
```csharp
334
using System;
335
using System.Net.Http;
336
using System.Net.Http.Headers;
337
using System.Text;
338
using System.Threading.Tasks;
339
using Newtonsoft.Json;
340
341
public class ChatCompletionExample
342
{
343
public static async Task Main(string[] args)
344
{
345
using (var client = new HttpClient())
346
{
347
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
348
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
349
350
var requestBody = new
351
{
352
model = "GPT-4 Turbo",
353
messages = new[]
354
{
355
new { role = "system", content = "You are a helpful assistant." },
356
new { role = "user", content = "What is the capital of France?" }
357
}
358
};
359
360
var json = JsonConvert.SerializeObject(requestBody);
361
var content = new StringContent(json, Encoding.UTF8, "application/json");
362
363
var response = await client.PostAsync("https://chatapi.ai-now.space/chat/completions", content);
364
var responseString = await response.Content.ReadAsStringAsync();
365
366
Console.WriteLine(responseString);
367
}
368
}
369
}
370
```
371
cdc885 admin 2024-08-22 16:03:54 372
#### Streaming Example
445f4f admin 2024-08-22 15:52:53 373
374
```csharp
375
using System;
376
using System.Net.Http;
377
using System.Net.Http.Headers;
378
using System.Text;
379
using System.Threading.Tasks;
380
using Newtonsoft.Json;
381
382
public class ChatCompletionStreamingExample
383
{
384
public static async Task Main(string[] args)
385
{
386
using (var client = new HttpClient())
387
{
388
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
389
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
390
391
var requestBody = new
392
{
393
model = "Claude 3.5 Sonnet",
394
messages = new[]
395
{
396
new { role = "system", content = "You are a helpful assistant." },
397
new { role = "user", content = "Write a short poem about the sea." }
398
},
399
stream = true
400
};
401
402
var json = JsonConvert.SerializeObject(requestBody);
403
var content = new StringContent(json, Encoding.UTF8, "application/json");
404
405
var response = await client.PostAsync("https://chatapi.ai-now.space/chat/completions", content);
406
407
using (var stream = await response.Content.ReadAsStreamAsync())
408
using (var reader = new System.IO.StreamReader(stream))
409
{
410
string line;
411
while ((line = await reader.ReadLineAsync()) != null)
412
{
413
if (line.StartsWith("data: "))
414
{
415
Console.WriteLine(line.Substring(6));
416
}
417
}
418
}
419
}
420
}
421
}
422
```
423
cdc885 admin 2024-08-22 16:03:54 424
### Node.js
445f4f admin 2024-08-22 15:52:53 425
cdc885 admin 2024-08-22 16:03:54 426
#### Non-Streaming Example
445f4f admin 2024-08-22 15:52:53 427
428
```javascript
429
const axios = require('axios');
430
431
const headers = {
432
'Authorization': 'Bearer YOUR_API_KEY',
433
'Content-Type': 'application/json'
434
};
435
436
const data = {
437
model: 'GPT-4 Turbo',
438
messages: [
439
{ role: 'system', content: 'You are a helpful assistant.' },
440
{ role: 'user', content: 'What is the capital of France?' }
441
]
442
};
443
444
axios.post('https://chatapi.ai-now.space/chat/completions', data, { headers })
445
.then(response => {
446
console.log(response.data);
447
})
448
.catch(error => {
449
console.error(error);
450
});
451
```
452
cdc885 admin 2024-08-22 16:03:54 453
#### Streaming Example
445f4f admin 2024-08-22 15:52:53 454
455
```javascript
456
const axios = require('axios');
457
458
const headers = {
459
'Authorization': 'Bearer YOUR_API_KEY',
460
'Content-Type': 'application/json'
461
};
462
463
const data = {
464
model: 'Claude 3.5 Sonnet',
465
messages: [
466
{ role: 'system', content: 'You are a helpful assistant.' },
467
{ role: 'user', content: 'Write a short poem about the sea.' }
468
],
469
stream: true
470
};
471
472
axios.post('https://chatapi.ai-now.space/chat/completions', data, { headers, responseType: 'stream' })
473
.then(response => {
474
response.data.on('data', (chunk) => {
475
const lines = chunk.toString().split('\n');
476
lines.forEach(line => {
477
if (line.startsWith('data: ')) {
478
console.log(line.substring(6));
479
}
480
});
481
});
482
})
483
.catch(error => {
484
console.error(error);
485
});
486
```
487
488
**Remember to replace `YOUR_API_KEY` with your actual API key.**
cdc885 admin 2024-08-22 16:03:54 489
```
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9