cencori 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Cencori
|
|
2
2
|
|
|
3
|
-
Official SDK for
|
|
3
|
+
Official SDK for Cencori - The Security Layer for AI Development.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,14 +8,16 @@ Official SDK for the Cencori.
|
|
|
8
8
|
npm install cencori
|
|
9
9
|
# or
|
|
10
10
|
yarn add cencori
|
|
11
|
+
# or
|
|
12
|
+
pnpm add cencori
|
|
11
13
|
```
|
|
12
14
|
|
|
13
15
|
## Quick Start
|
|
14
16
|
|
|
15
17
|
```typescript
|
|
16
|
-
import {
|
|
18
|
+
import { Cencori } from 'cencori';
|
|
17
19
|
|
|
18
|
-
const cencori = new
|
|
20
|
+
const cencori = new Cencori({
|
|
19
21
|
apiKey: process.env.CENCORI_API_KEY!
|
|
20
22
|
});
|
|
21
23
|
|
|
@@ -33,19 +35,23 @@ console.log(response.content);
|
|
|
33
35
|
Get your API key from the [Cencori Dashboard](https://cencori.com/dashboard):
|
|
34
36
|
|
|
35
37
|
1. Create a project
|
|
36
|
-
2. Navigate to API
|
|
37
|
-
3. Generate a new key
|
|
38
|
+
2. Navigate to Settings → API tab
|
|
39
|
+
3. Generate a new key:
|
|
40
|
+
- **Secret key (`csk_`)** - For server-side use only
|
|
41
|
+
- **Publishable key (`cpk_`)** - Safe for browser use (requires domain whitelisting)
|
|
38
42
|
4. Copy and store it securely
|
|
39
43
|
|
|
40
44
|
## API Reference
|
|
41
45
|
|
|
42
|
-
###
|
|
46
|
+
### Cencori
|
|
43
47
|
|
|
44
48
|
Initialize the SDK client.
|
|
45
49
|
|
|
46
50
|
```typescript
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
import { Cencori } from 'cencori';
|
|
52
|
+
|
|
53
|
+
const cencori = new Cencori({
|
|
54
|
+
apiKey: 'csk_xxx', // Secret key for server-side
|
|
49
55
|
baseUrl: 'https://cencori.com' // Optional, defaults to production
|
|
50
56
|
});
|
|
51
57
|
```
|
|
@@ -54,13 +60,14 @@ const cencori = new CencoriClient({
|
|
|
54
60
|
|
|
55
61
|
#### `ai.chat(params)`
|
|
56
62
|
|
|
57
|
-
Send a chat message to the AI.
|
|
63
|
+
Send a chat message to the AI (non-streaming).
|
|
58
64
|
|
|
59
65
|
**Parameters:**
|
|
60
|
-
- `messages`: Array of message objects with `role` ('user' | 'assistant') and `content`
|
|
61
|
-
- `model`: Optional AI model (defaults to 'gemini-
|
|
66
|
+
- `messages`: Array of message objects with `role` ('system' | 'user' | 'assistant') and `content`
|
|
67
|
+
- `model`: Optional AI model (defaults to 'gemini-2.5-flash')
|
|
62
68
|
- `temperature`: Optional temperature (0-1)
|
|
63
|
-
- `
|
|
69
|
+
- `maxTokens`: Optional max tokens for response
|
|
70
|
+
- `userId`: Optional user ID for rate limiting
|
|
64
71
|
|
|
65
72
|
**Example:**
|
|
66
73
|
|
|
@@ -69,11 +76,32 @@ const response = await cencori.ai.chat({
|
|
|
69
76
|
messages: [
|
|
70
77
|
{ role: 'user', content: 'Explain quantum computing' }
|
|
71
78
|
],
|
|
79
|
+
model: 'gpt-4o',
|
|
72
80
|
temperature: 0.7
|
|
73
81
|
});
|
|
74
82
|
|
|
75
83
|
console.log(response.content);
|
|
76
84
|
console.log(response.usage); // Token usage stats
|
|
85
|
+
console.log(response.cost_usd); // Cost in USD
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### `ai.chatStream(params)`
|
|
89
|
+
|
|
90
|
+
Stream a chat response token-by-token.
|
|
91
|
+
|
|
92
|
+
**Example:**
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const stream = cencori.ai.chatStream({
|
|
96
|
+
messages: [
|
|
97
|
+
{ role: 'user', content: 'Tell me a story' }
|
|
98
|
+
],
|
|
99
|
+
model: 'gpt-4o'
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
for await (const chunk of stream) {
|
|
103
|
+
process.stdout.write(chunk.delta);
|
|
104
|
+
}
|
|
77
105
|
```
|
|
78
106
|
|
|
79
107
|
## Error Handling
|
|
@@ -82,7 +110,7 @@ The SDK includes custom error classes for common scenarios:
|
|
|
82
110
|
|
|
83
111
|
```typescript
|
|
84
112
|
import {
|
|
85
|
-
|
|
113
|
+
Cencori,
|
|
86
114
|
AuthenticationError,
|
|
87
115
|
RateLimitError,
|
|
88
116
|
SafetyError
|
|
@@ -106,34 +134,58 @@ try {
|
|
|
106
134
|
The SDK is written in TypeScript and includes full type definitions.
|
|
107
135
|
|
|
108
136
|
```typescript
|
|
109
|
-
import type { ChatParams, ChatResponse, Message } from 'cencori';
|
|
137
|
+
import type { ChatParams, ChatResponse, Message, StreamChunk } from 'cencori';
|
|
110
138
|
```
|
|
111
139
|
|
|
112
140
|
## Features
|
|
113
141
|
|
|
114
|
-
- Full TypeScript support with type definitions
|
|
115
|
-
- Built-in authentication
|
|
116
|
-
- Automatic retry logic with exponential backoff
|
|
117
|
-
- Custom error classes
|
|
118
|
-
- Content safety filtering
|
|
119
|
-
- Rate limiting protection
|
|
142
|
+
- ✅ Full TypeScript support with type definitions
|
|
143
|
+
- ✅ Built-in authentication
|
|
144
|
+
- ✅ Automatic retry logic with exponential backoff
|
|
145
|
+
- ✅ Custom error classes
|
|
146
|
+
- ✅ Content safety filtering (PII, prompt injection, harmful content)
|
|
147
|
+
- ✅ Rate limiting protection
|
|
148
|
+
- ✅ Streaming support with `chatStream()`
|
|
149
|
+
|
|
150
|
+
## Supported Models
|
|
151
|
+
|
|
152
|
+
| Provider | Models |
|
|
153
|
+
|----------|--------|
|
|
154
|
+
| OpenAI | `gpt-4o`, `gpt-4-turbo`, `gpt-3.5-turbo` |
|
|
155
|
+
| Anthropic | `claude-3-opus`, `claude-3-sonnet`, `claude-3-haiku` |
|
|
156
|
+
| Google | `gemini-2.5-flash`, `gemini-2.0-flash` |
|
|
120
157
|
|
|
121
158
|
## Local Development
|
|
122
159
|
|
|
123
160
|
For local development or testing:
|
|
124
161
|
|
|
125
162
|
```typescript
|
|
126
|
-
const cencori = new
|
|
127
|
-
apiKey: '
|
|
163
|
+
const cencori = new Cencori({
|
|
164
|
+
apiKey: 'csk_test_xxx', // Test secret key
|
|
128
165
|
baseUrl: 'http://localhost:3000'
|
|
129
166
|
});
|
|
130
167
|
```
|
|
131
168
|
|
|
169
|
+
## Browser Usage (Publishable Keys)
|
|
170
|
+
|
|
171
|
+
For browser/client-side usage, use publishable keys:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// Safe to use in browser - only works from allowed domains
|
|
175
|
+
const cencori = new Cencori({
|
|
176
|
+
apiKey: 'cpk_xxx' // Publishable key
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const response = await cencori.ai.chat({
|
|
180
|
+
messages: [{ role: 'user', content: 'Hello!' }]
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
132
184
|
## Support
|
|
133
185
|
|
|
134
|
-
- **Documentation**: [
|
|
186
|
+
- **Documentation**: [cencori.com/docs](https://cencori.com/docs)
|
|
135
187
|
- **Dashboard**: [cencori.com/dashboard](https://cencori.com/dashboard)
|
|
136
|
-
- **GitHub**: [github.com/
|
|
188
|
+
- **GitHub**: [github.com/cencori](https://github.com/cencori)
|
|
137
189
|
|
|
138
190
|
## License
|
|
139
191
|
|