npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

krutrim-ai-sdk

v0.1.1

Published

Krutrim Cloud provider for the Vercel AI SDK — chat, streaming, tools, embeddings & Indic helpers for India's sovereign AI platform

Readme

krutrim-ai-sdk


Why this exists

Krutrim Cloud already has an OpenAI-compatible API. You can point the raw OpenAI client at https://cloud.olakrutrim.com/v1 and ship.

Building real products needs more:

  • First-class Vercel AI SDK support — generateText, streamText, tools, structured output, Next.js streaming — not a second-class fork of openai
  • Model aliases that stick — krutrim-2 → Krutrim-2, without hunting catalogue strings
  • Indic-native defaults — Hindi/Tamil/Malayalam system prompts, Hinglish notes, support-agent presets, ₹/INR-aware errors
  • Clear failure modes — rate limits, credits, region, bad keys — explained for Indian builders, not generic US SaaS copy

I built krutrim-ai-sdk so Krutrim works with the same DX as other AI SDK providers (similar spirit to sarvam-ai-sdk): solid defaults, typed APIs, and production-ready ergonomics.


Install (one command)

npm i krutrim-ai-sdk ai@6
pnpm add krutrim-ai-sdk ai@6
# or
yarn add krutrim-ai-sdk ai@6
# or
bun add krutrim-ai-sdk ai@6

Get an API key from the Krutrim Cloud console:

# .env — either name works
KRUTRIM_API_KEY=your_api_key_here
# KRUTRIM_CLOUD_API_KEY=your_api_key_here

Quick start

1. Basic chat

import { krutrim } from 'krutrim-ai-sdk';
import { generateText } from 'ai';

const { text } = await generateText({
  model: krutrim('Krutrim-2'),
  prompt: 'नमस्ते! मुंबई के बारे में एक मज़ेदार तथ्य बताओ।',
});

console.log(text);

2. Streaming

import { streamText } from 'ai';
import { krutrim } from 'krutrim-ai-sdk';

const result = streamText({
  model: krutrim('Krutrim-2'),
  prompt: 'Write a short poem about the Indian monsoon.',
});

for await (const delta of result.textStream) {
  process.stdout.write(delta);
}

3. Next.js App Router

app/api/chat/route.ts:

import { streamText, convertToModelMessages, type UIMessage } from 'ai';
import { krutrim, indicResponsePrompt } from 'krutrim-ai-sdk';

export const maxDuration = 60;

export async function POST(req: Request) {
  const { messages }: { messages: UIMessage[] } = await req.json();

  const result = streamText({
    model: krutrim('Krutrim-2'),
    system: indicResponsePrompt('en-IN', { allowCodeMix: true }),
    messages: await convertToModelMessages(messages),
  });

  return result.toUIMessageStreamResponse();
}

Wire any AI SDK UI (useChat) to POST /api/chat.

4. Agent with tools

import { generateText, tool, stepCountIs } from 'ai';
import { z } from 'zod';
import { krutrim, indicSupportAgentPrompt } from 'krutrim-ai-sdk';

const result = await generateText({
  model: krutrim('Krutrim-2'),
  system: indicSupportAgentPrompt({
    brandName: 'MyApp',
    languages: ['hi-IN', 'en-IN', 'ta-IN'],
  }),
  tools: {
    lookupOrder: tool({
      description: 'Look up an order by ID',
      inputSchema: z.object({ orderId: z.string() }),
      execute: async ({ orderId }) => ({
        orderId,
        status: 'Shipped',
        amountInr: 1499,
      }),
    }),
  },
  stopWhen: stepCountIs(5),
  prompt: 'Mera order ORD-9912 kahan hai?',
});

console.log(result.text);

5. Custom provider config

import { createKrutrim } from 'krutrim-ai-sdk';

const krutrim = createKrutrim({
  apiKey: process.env.KRUTRIM_API_KEY,
  baseURL: 'https://cloud.olakrutrim.com/v1',
  headers: { 'X-App-Name': 'my-app' },
});

Supported models

IDs follow the Krutrim Model Catalogue. Confirm in the console if a call returns “invalid model”.

Native Krutrim (highlight)

| Model | ID | Modality | | ----- | -- | -------- | | Krutrim-2 | Krutrim-2 / alias krutrim-2 | Text ★ default pick | | Krutrim-1 | Krutrim-1 / alias krutrim-1 | Text | | Krutrim-Dhwani | Krutrim-Dhwani | Speech-to-Text | | Krutrim-TTS | Krutrim-TTS | Text-to-Speech | | Vyakyarth | Vyakyarth | Embeddings | | Bhasantarit | Bhasantarit | Embeddings | | chitrapathak | chitrapathak | Vision / image-text |

Popular hosted open models

| Model | ID | | ----- | -- | | Llama 3.3 70B | Llama-3.3-70B-Instruct | | Llama 3.2 11B Vision | Llama-3.2-11B-Vision-Instruct | | DeepSeek R1 | DeepSeek-R1 | | Qwen3 32B | Qwen3-32B | | Mistral 7B | Mistral-7B-v0.2 | | Phi-4 Reasoning | Phi-4-reasoning-plus | | Gemma 3 27B | gemma-3-27b-it |

import { KRUTRIM_CHAT_MODELS, resolveModelId } from 'krutrim-ai-sdk';

krutrim(KRUTRIM_CHAT_MODELS.krutrim2);
resolveModelId('deepseek-r1'); // → "DeepSeek-R1"

krutrim-ai-sdk vs raw OpenAI SDK

| | OpenAI SDK pointed at Krutrim | krutrim-ai-sdk | | - | ----------------------------- | ------------------ | | Works with AI SDK generateText / streamText | Manual / wrappers | ✅ native | | Next.js UI message streaming | DIY | ✅ toUIMessageStreamResponse | | Tool calling + agents | DIY mapping | ✅ first-class | | Model aliases (krutrim-2) | ❌ | ✅ | | Indic system prompts | ❌ | ✅ indicResponsePrompt, etc. | | INR / rate-limit error tips | Generic | ✅ India-aware | | Embeddings + Bhashik helpers | Separate clients | ✅ same package | | Dependencies | openai client | Minimal (@ai-sdk/*) |

You still use Krutrim’s OpenAI-compatible endpoint under the hood — this package is the AI SDK-shaped door into it.


Indic helpers 🇮🇳

import {
  indicResponsePrompt,
  transliterationNotes,
  indicSupportAgentPrompt,
  INDIC_LANGUAGES,
} from 'krutrim-ai-sdk';

// Force native-script Hindi answers
indicResponsePrompt('hi-IN');

// Hinglish / Romanized input awareness
transliterationNotes('hi-IN');

// Support agent: mirrors language, uses ₹ when relevant
indicSupportAgentPrompt({ brandName: 'PayApp' });

Bhashik / TTT helpers (Sarvam-style surface)

Same idea as sarvam-ai-sdk: language ID, translation, transliteration, speech, STT — plus Krutrim extras.

// Language detection (also: languageIdentification())
await generateText({
  model: krutrim.languageDetection(),
  prompt: 'എന്തൊരു മനോഹരമായ ദിവസം!',
});

// Translation
await generateText({
  model: krutrim.translation({ from: 'hi-IN', to: 'en-IN' }),
  prompt: 'आज मौसम बहुत सुहाना है।',
});

// Transliteration (chat-backed; same DX as Sarvam)
await generateText({
  model: krutrim.transliterate({ to: 'hi-IN', from: 'en-IN' }),
  prompt: 'namaste, aap kaise ho?',
});

// Summarization / sentiment (Bhashik Language Labs)
await generateText({
  model: krutrim.summarization({ language: 'hin', summarySize: 40 }),
  prompt: '…long Hindi article…',
});
await generateText({
  model: krutrim.sentiment({ language: 'eng' }),
  prompt: 'The service was excellent!',
});

// Embeddings
await embed({
  model: krutrim.embedding('Vyakyarth'),
  value: 'भारत की राजधानी नई दिल्ली है।',
});

Version compatibility

| krutrim-ai-sdk | Vercel AI SDK | | -------------- | ------------- | | 0.1.x (current) | 6.x | | 0.2.x (planned) | 7.x |

Same generation as sarvam-ai-sdk 0.3.x (AI SDK v6 / LanguageModelV3).


API surface

import { krutrim } from 'krutrim-ai-sdk';

// Chat
krutrim('Krutrim-2');
krutrim.languageModel('Llama-3.3-70B-Instruct');
krutrim.chat('deepseek-r1');

// Embeddings
krutrim.embedding('Vyakyarth');
krutrim.textEmbeddingModel('Bhasantarit');

// Speech / STT (language-first or Sarvam-style model + language)
krutrim.speech('hi-IN');
krutrim.speech('Krutrim-TTS', 'hi-IN');
krutrim.transcription('ta-IN');
krutrim.transcription('Krutrim-Dhwani', 'ta-IN');

// Language ID / translation / transliterate
krutrim.languageDetection();
krutrim.languageIdentification(); // alias
krutrim.translation({ from: 'hi-IN', to: 'en-IN' });
krutrim.translation('krutrim-translate-v1.0', { from: 'hi-IN', to: 'en-IN' });
krutrim.transliterate({ to: 'hi-IN', from: 'en-IN' });

// Bhashik extras
krutrim.summarization({ language: 'hin' });
krutrim.sentiment({ language: 'eng' });

Base URL: https://cloud.olakrutrim.com/v1
Docs: Inferencing · Model catalogue


Examples

| File | Demo | | ---- | ---- | | examples/generate-text.ts | Hindi chat | | examples/stream-text.ts | Streaming | | examples/tools.ts | Tool calling | | examples/agent.ts | Multilingual agent | | examples/structured-output.ts | Structured JSON | | examples/embeddings.ts | Embeddings | | examples/nextjs-app-router/route.ts | App Router |

cp .env.example .env
npm i
npx tsx --env-file=.env examples/generate-text.ts

Roadmap

  • [x] Chat completions (generate + stream)
  • [x] Tool calling & structured output path
  • [x] Model aliases + models.ts constants
  • [x] Indic prompt helpers + India-aware errors
  • [x] Embeddings (Vyakyarth / Bhasantarit)
  • [x] Bhashik TTS / STT / LID / translation (lightweight)
  • [x] Transliterate + languageIdentification (Sarvam-compatible surface)
  • [x] Summarization + sentiment (Bhashik)
  • [ ] Official listing under AI SDK community providers
  • [ ] Image generation helpers (diffusion / multimodal)
  • [ ] AI SDK v7 (LanguageModelV4) track
  • [ ] More integration tests + sample apps (chat UI, voice)

Vote with ⭐ and Issues — popular requests get prioritized.


Contributing

PRs and issues are welcome. See CONTRIBUTING.md.

npm i
npm run build
npm test

Disclaimer

Unofficial project — not affiliated with or endorsed by Ola / Krutrim unless stated otherwise. Maintained by aljojoby9.


Links

License

MIT · © aljojoby9