krutrim-ai-sdk 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] — 2026-07-13
9
+
10
+ ### Added
11
+
12
+ - Initial public release of **krutrim-ai-sdk**
13
+ - `createKrutrim` / default `krutrim` provider for Vercel AI SDK v6
14
+ - Chat completions: `generateText`, `streamText`, tool calling, structured output path
15
+ - OpenAI-compatible client for `https://cloud.olakrutrim.com/v1`
16
+ - API key via `KRUTRIM_API_KEY` or `KRUTRIM_CLOUD_API_KEY`
17
+ - Model aliases and exports (`KRUTRIM_CHAT_MODELS`, `resolveModelId`, …)
18
+ - Embedding models (`embedding` / `textEmbeddingModel`)
19
+ - Lightweight Bhashik helpers: speech (TTS), transcription (STT), language detection, translation
20
+ - Indic helpers: `indicResponsePrompt`, `transliterationNotes`, `indicSupportAgentPrompt`, language maps
21
+ - India-aware error enrichment (rate limits, INR credits, region, invalid model)
22
+ - Examples, tests, MIT license, contributing docs
23
+
24
+ [0.1.0]: https://github.com/aljojoby9/krutrim-ai-sdk/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 aljojoby9
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,365 @@
1
+ # krutrim-ai-sdk
2
+
3
+ <p align="center">
4
+ <strong>Vercel AI SDK provider for <a href="https://cloud.olakrutrim.com">Krutrim Cloud</a></strong><br/>
5
+ India's sovereign AI — with DX Indian developers actually enjoy.
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/krutrim-ai-sdk"><img src="https://img.shields.io/npm/v/krutrim-ai-sdk.svg?color=cb3837" alt="npm version" /></a>
10
+ <a href="https://www.npmjs.com/package/krutrim-ai-sdk"><img src="https://img.shields.io/npm/dm/krutrim-ai-sdk.svg?color=blue" alt="npm downloads" /></a>
11
+ <a href="https://github.com/aljojoby9/krutrim-ai-sdk/stargazers"><img src="https://img.shields.io/github/stars/aljojoby9/krutrim-ai-sdk?style=social" alt="GitHub stars" /></a>
12
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License" /></a>
13
+ <a href="https://ai-sdk.dev"><img src="https://img.shields.io/badge/AI%20SDK-v6-black" alt="AI SDK v6" /></a>
14
+ <img src="https://img.shields.io/badge/Made%20in-India-FF9933?labelColor=138808" alt="Made in India" />
15
+ </p>
16
+
17
+ <p align="center">
18
+ Chat · Streaming · Tools · Agents · Embeddings · Indic helpers · Bhashik speech<br/>
19
+ <code>npm i krutrim-ai-sdk ai@6</code>
20
+ </p>
21
+
22
+ ---
23
+
24
+ ## Why this exists
25
+
26
+ Krutrim Cloud already has an **OpenAI-compatible** API. You *can* point the raw OpenAI client at `https://cloud.olakrutrim.com/v1` and ship.
27
+
28
+ Building real products needs more:
29
+
30
+ - **First-class Vercel AI SDK support** — `generateText`, `streamText`, tools, structured output, Next.js streaming — not a second-class fork of `openai`
31
+ - **Model aliases that stick** — `krutrim-2` → `Krutrim-2`, without hunting catalogue strings
32
+ - **Indic-native defaults** — Hindi/Tamil/Malayalam system prompts, Hinglish notes, support-agent presets, ₹/INR-aware errors
33
+ - **Clear failure modes** — rate limits, credits, region, bad keys — explained for Indian builders, not generic US SaaS copy
34
+
35
+ I built **krutrim-ai-sdk** so Krutrim works with the same DX as other AI SDK providers (similar spirit to [sarvam-ai-sdk](https://github.com/sarvamai/sarvam-ai-sdk)): solid defaults, typed APIs, and production-ready ergonomics.
36
+
37
+ ---
38
+
39
+ ## Install (one command)
40
+
41
+ ```bash
42
+ npm i krutrim-ai-sdk ai@6
43
+ ```
44
+
45
+ ```bash
46
+ pnpm add krutrim-ai-sdk ai@6
47
+ # or
48
+ yarn add krutrim-ai-sdk ai@6
49
+ # or
50
+ bun add krutrim-ai-sdk ai@6
51
+ ```
52
+
53
+ Get an API key from the [Krutrim Cloud console](https://cloud.olakrutrim.com):
54
+
55
+ ```bash
56
+ # .env — either name works
57
+ KRUTRIM_API_KEY=your_api_key_here
58
+ # KRUTRIM_CLOUD_API_KEY=your_api_key_here
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Quick start
64
+
65
+ ### 1. Basic chat
66
+
67
+ ```ts
68
+ import { krutrim } from 'krutrim-ai-sdk';
69
+ import { generateText } from 'ai';
70
+
71
+ const { text } = await generateText({
72
+ model: krutrim('Krutrim-2'),
73
+ prompt: 'नमस्ते! मुंबई के बारे में एक मज़ेदार तथ्य बताओ।',
74
+ });
75
+
76
+ console.log(text);
77
+ ```
78
+
79
+ ### 2. Streaming
80
+
81
+ ```ts
82
+ import { streamText } from 'ai';
83
+ import { krutrim } from 'krutrim-ai-sdk';
84
+
85
+ const result = streamText({
86
+ model: krutrim('Krutrim-2'),
87
+ prompt: 'Write a short poem about the Indian monsoon.',
88
+ });
89
+
90
+ for await (const delta of result.textStream) {
91
+ process.stdout.write(delta);
92
+ }
93
+ ```
94
+
95
+ ### 3. Next.js App Router
96
+
97
+ `app/api/chat/route.ts`:
98
+
99
+ ```ts
100
+ import { streamText, convertToModelMessages, type UIMessage } from 'ai';
101
+ import { krutrim, indicResponsePrompt } from 'krutrim-ai-sdk';
102
+
103
+ export const maxDuration = 60;
104
+
105
+ export async function POST(req: Request) {
106
+ const { messages }: { messages: UIMessage[] } = await req.json();
107
+
108
+ const result = streamText({
109
+ model: krutrim('Krutrim-2'),
110
+ system: indicResponsePrompt('en-IN', { allowCodeMix: true }),
111
+ messages: await convertToModelMessages(messages),
112
+ });
113
+
114
+ return result.toUIMessageStreamResponse();
115
+ }
116
+ ```
117
+
118
+ Wire any AI SDK UI (`useChat`) to `POST /api/chat`.
119
+
120
+ ### 4. Agent with tools
121
+
122
+ ```ts
123
+ import { generateText, tool, stepCountIs } from 'ai';
124
+ import { z } from 'zod';
125
+ import { krutrim, indicSupportAgentPrompt } from 'krutrim-ai-sdk';
126
+
127
+ const result = await generateText({
128
+ model: krutrim('Krutrim-2'),
129
+ system: indicSupportAgentPrompt({
130
+ brandName: 'MyApp',
131
+ languages: ['hi-IN', 'en-IN', 'ta-IN'],
132
+ }),
133
+ tools: {
134
+ lookupOrder: tool({
135
+ description: 'Look up an order by ID',
136
+ inputSchema: z.object({ orderId: z.string() }),
137
+ execute: async ({ orderId }) => ({
138
+ orderId,
139
+ status: 'Shipped',
140
+ amountInr: 1499,
141
+ }),
142
+ }),
143
+ },
144
+ stopWhen: stepCountIs(5),
145
+ prompt: 'Mera order ORD-9912 kahan hai?',
146
+ });
147
+
148
+ console.log(result.text);
149
+ ```
150
+
151
+ ### 5. Custom provider config
152
+
153
+ ```ts
154
+ import { createKrutrim } from 'krutrim-ai-sdk';
155
+
156
+ const krutrim = createKrutrim({
157
+ apiKey: process.env.KRUTRIM_API_KEY,
158
+ baseURL: 'https://cloud.olakrutrim.com/v1',
159
+ headers: { 'X-App-Name': 'my-app' },
160
+ });
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Supported models
166
+
167
+ IDs follow the [Krutrim Model Catalogue](https://docs.cloud.olakrutrim.com/basics/ai-studio/model-catalogue). Confirm in the console if a call returns “invalid model”.
168
+
169
+ ### Native Krutrim (highlight)
170
+
171
+ | Model | ID | Modality |
172
+ | ----- | -- | -------- |
173
+ | **Krutrim-2** | `Krutrim-2` / alias `krutrim-2` | Text ★ default pick |
174
+ | **Krutrim-1** | `Krutrim-1` / alias `krutrim-1` | Text |
175
+ | **Krutrim-Dhwani** | `Krutrim-Dhwani` | Speech-to-Text |
176
+ | **Krutrim-TTS** | `Krutrim-TTS` | Text-to-Speech |
177
+ | **Vyakyarth** | `Vyakyarth` | Embeddings |
178
+ | **Bhasantarit** | `Bhasantarit` | Embeddings |
179
+ | **chitrapathak** | `chitrapathak` | Vision / image-text |
180
+
181
+ ### Popular hosted open models
182
+
183
+ | Model | ID |
184
+ | ----- | -- |
185
+ | Llama 3.3 70B | `Llama-3.3-70B-Instruct` |
186
+ | Llama 3.2 11B Vision | `Llama-3.2-11B-Vision-Instruct` |
187
+ | DeepSeek R1 | `DeepSeek-R1` |
188
+ | Qwen3 32B | `Qwen3-32B` |
189
+ | Mistral 7B | `Mistral-7B-v0.2` |
190
+ | Phi-4 Reasoning | `Phi-4-reasoning-plus` |
191
+ | Gemma 3 27B | `gemma-3-27b-it` |
192
+
193
+ ```ts
194
+ import { KRUTRIM_CHAT_MODELS, resolveModelId } from 'krutrim-ai-sdk';
195
+
196
+ krutrim(KRUTRIM_CHAT_MODELS.krutrim2);
197
+ resolveModelId('deepseek-r1'); // → "DeepSeek-R1"
198
+ ```
199
+
200
+ ---
201
+
202
+ ## krutrim-ai-sdk vs raw OpenAI SDK
203
+
204
+ | | OpenAI SDK pointed at Krutrim | **krutrim-ai-sdk** |
205
+ | - | ----------------------------- | ------------------ |
206
+ | Works with AI SDK `generateText` / `streamText` | Manual / wrappers | ✅ native |
207
+ | Next.js UI message streaming | DIY | ✅ `toUIMessageStreamResponse` |
208
+ | Tool calling + agents | DIY mapping | ✅ first-class |
209
+ | Model aliases (`krutrim-2`) | ❌ | ✅ |
210
+ | Indic system prompts | ❌ | ✅ `indicResponsePrompt`, etc. |
211
+ | INR / rate-limit error tips | Generic | ✅ India-aware |
212
+ | Embeddings + Bhashik helpers | Separate clients | ✅ same package |
213
+ | Dependencies | `openai` client | Minimal (`@ai-sdk/*`) |
214
+
215
+ You still use Krutrim’s OpenAI-compatible endpoint under the hood — this package is the **AI SDK-shaped door** into it.
216
+
217
+ ---
218
+
219
+ ## Indic helpers 🇮🇳
220
+
221
+ ```ts
222
+ import {
223
+ indicResponsePrompt,
224
+ transliterationNotes,
225
+ indicSupportAgentPrompt,
226
+ INDIC_LANGUAGES,
227
+ } from 'krutrim-ai-sdk';
228
+
229
+ // Force native-script Hindi answers
230
+ indicResponsePrompt('hi-IN');
231
+
232
+ // Hinglish / Romanized input awareness
233
+ transliterationNotes('hi-IN');
234
+
235
+ // Support agent: mirrors language, uses ₹ when relevant
236
+ indicSupportAgentPrompt({ brandName: 'PayApp' });
237
+ ```
238
+
239
+ ### Bhashik extras
240
+
241
+ ```ts
242
+ // Language detection
243
+ await generateText({
244
+ model: krutrim.languageDetection(),
245
+ prompt: 'എന്തൊരു മനോഹരമായ ദിവസം!',
246
+ });
247
+
248
+ // Translation
249
+ await generateText({
250
+ model: krutrim.translation({ from: 'hi-IN', to: 'en-IN' }),
251
+ prompt: 'आज मौसम बहुत सुहाना है।',
252
+ });
253
+
254
+ // Embeddings
255
+ await embed({
256
+ model: krutrim.embedding('Vyakyarth'),
257
+ value: 'भारत की राजधानी नई दिल्ली है।',
258
+ });
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Version compatibility
264
+
265
+ | krutrim-ai-sdk | Vercel AI SDK |
266
+ | -------------- | ------------- |
267
+ | **0.1.x** (current) | **6.x** |
268
+ | 0.2.x (planned) | 7.x |
269
+
270
+ > Same generation as [sarvam-ai-sdk](https://www.npmjs.com/package/sarvam-ai-sdk) `0.3.x` (AI SDK v6 / `LanguageModelV3`).
271
+
272
+ ---
273
+
274
+ ## API surface
275
+
276
+ ```ts
277
+ import { krutrim } from 'krutrim-ai-sdk';
278
+
279
+ // Chat
280
+ krutrim('Krutrim-2');
281
+ krutrim.languageModel('Llama-3.3-70B-Instruct');
282
+ krutrim.chat('deepseek-r1');
283
+
284
+ // Embeddings
285
+ krutrim.embedding('Vyakyarth');
286
+ krutrim.textEmbeddingModel('Bhasantarit');
287
+
288
+ // Bhashik / Language Labs
289
+ krutrim.speech('hi-IN');
290
+ krutrim.transcription('ta-IN');
291
+ krutrim.languageDetection();
292
+ krutrim.translation({ from: 'hi-IN', to: 'en-IN' });
293
+ ```
294
+
295
+ Base URL: `https://cloud.olakrutrim.com/v1`
296
+ Docs: [Inferencing](https://docs.cloud.olakrutrim.com/basics/ai-studio/ai-jobs/inferencing) · [Model catalogue](https://docs.cloud.olakrutrim.com/basics/ai-studio/model-catalogue)
297
+
298
+ ---
299
+
300
+ ## Examples
301
+
302
+ | File | Demo |
303
+ | ---- | ---- |
304
+ | [`examples/generate-text.ts`](./examples/generate-text.ts) | Hindi chat |
305
+ | [`examples/stream-text.ts`](./examples/stream-text.ts) | Streaming |
306
+ | [`examples/tools.ts`](./examples/tools.ts) | Tool calling |
307
+ | [`examples/agent.ts`](./examples/agent.ts) | Multilingual agent |
308
+ | [`examples/structured-output.ts`](./examples/structured-output.ts) | Structured JSON |
309
+ | [`examples/embeddings.ts`](./examples/embeddings.ts) | Embeddings |
310
+ | [`examples/nextjs-app-router/route.ts`](./examples/nextjs-app-router/route.ts) | App Router |
311
+
312
+ ```bash
313
+ cp .env.example .env
314
+ npm i
315
+ npx tsx --env-file=.env examples/generate-text.ts
316
+ ```
317
+
318
+ ---
319
+
320
+ ## Roadmap
321
+
322
+ - [x] Chat completions (generate + stream)
323
+ - [x] Tool calling & structured output path
324
+ - [x] Model aliases + `models.ts` constants
325
+ - [x] Indic prompt helpers + India-aware errors
326
+ - [x] Embeddings (Vyakyarth / Bhasantarit)
327
+ - [x] Bhashik TTS / STT / LID / translation (lightweight)
328
+ - [ ] Official listing under AI SDK [community providers](https://ai-sdk.dev/providers/community-providers)
329
+ - [ ] Image generation helpers (diffusion / multimodal)
330
+ - [ ] AI SDK v7 (`LanguageModelV4`) track
331
+ - [ ] More integration tests + sample apps (chat UI, voice)
332
+
333
+ Vote with ⭐ and Issues — popular requests get prioritized.
334
+
335
+ ---
336
+
337
+ ## Contributing
338
+
339
+ PRs and issues are welcome. See **[CONTRIBUTING.md](./CONTRIBUTING.md)**.
340
+
341
+ ```bash
342
+ npm i
343
+ npm run build
344
+ npm test
345
+ ```
346
+
347
+ ---
348
+
349
+ ## Disclaimer
350
+
351
+ Unofficial project — not affiliated with or endorsed by Ola / Krutrim unless stated otherwise. Maintained by [aljojoby9](https://github.com/aljojoby9).
352
+
353
+ ---
354
+
355
+ ## Links
356
+
357
+ - [Krutrim Cloud](https://cloud.olakrutrim.com)
358
+ - [Krutrim docs](https://docs.cloud.olakrutrim.com)
359
+ - [Vercel AI SDK](https://ai-sdk.dev)
360
+ - [Custom provider guide](https://ai-sdk.dev/providers/community-providers/custom-providers)
361
+ - [Sarvam AI SDK (inspiration)](https://github.com/sarvamai/sarvam-ai-sdk)
362
+
363
+ ## License
364
+
365
+ [MIT](./LICENSE) · © [aljojoby9](https://github.com/aljojoby9)