|
| 1 | +# @tanstack/ai-groq |
| 2 | + |
| 3 | +Groq adapter for TanStack AI |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @tanstack/ai-groq |
| 9 | +# or |
| 10 | +pnpm add @tanstack/ai-groq |
| 11 | +# or |
| 12 | +yarn add @tanstack/ai-groq |
| 13 | +``` |
| 14 | + |
| 15 | +## Setup |
| 16 | + |
| 17 | +Get your API key from [Groq Console](https://console.groq.com) and set it as an environment variable: |
| 18 | + |
| 19 | +```bash |
| 20 | +export GROQ_API_KEY="gsk_..." |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Text/Chat Adapter |
| 26 | + |
| 27 | +```typescript |
| 28 | +import { groqText } from '@tanstack/ai-groq' |
| 29 | +import { generate } from '@tanstack/ai' |
| 30 | + |
| 31 | +const adapter = groqText('llama-3.3-70b-versatile') |
| 32 | + |
| 33 | +const result = await generate({ |
| 34 | + adapter, |
| 35 | + model: 'llama-3.3-70b-versatile', |
| 36 | + messages: [ |
| 37 | + { role: 'user', content: 'Explain quantum computing in simple terms' }, |
| 38 | + ], |
| 39 | +}) |
| 40 | + |
| 41 | +console.log(result.text) |
| 42 | +``` |
| 43 | + |
| 44 | +### With Explicit API Key |
| 45 | + |
| 46 | +```typescript |
| 47 | +import { createGroqText } from '@tanstack/ai-groq' |
| 48 | + |
| 49 | +const adapter = createGroqText('llama-3.3-70b-versatile', 'gsk_api_key') |
| 50 | +``` |
| 51 | + |
| 52 | +## Supported Models |
| 53 | + |
| 54 | +### Chat Models |
| 55 | + |
| 56 | +- `llama-3.3-70b-versatile` - Meta Llama 3.3 70B (131k context) |
| 57 | +- `llama-3.1-8b-instant` - Meta Llama 3.1 8B (131k context) |
| 58 | +- `meta-llama/llama-4-maverick-17b-128e-instruct` - Meta Llama 4 Maverick (vision) |
| 59 | +- `meta-llama/llama-4-scout-17b-16e-instruct` - Meta Llama 4 Scout |
| 60 | +- `meta-llama/llama-guard-4-12b` - Meta Llama Guard 4 (content moderation, vision) |
| 61 | +- `meta-llama/llama-prompt-guard-2-86m` - Meta Llama Prompt Guard (content moderation) |
| 62 | +- `meta-llama/llama-prompt-guard-2-22m` - Meta Llama Prompt Guard (content moderation) |
| 63 | +- `openai/gpt-oss-120b` - GPT OSS 120B (reasoning, tools, search) |
| 64 | +- `openai/gpt-oss-20b` - GPT OSS 20B (reasoning, search) |
| 65 | +- `openai/gpt-oss-safeguard-20b` - GPT OSS Safeguard 20B (content moderation, reasoning) |
| 66 | +- `moonshotai/kimi-k2-instruct-0905` - Kimi K2 Instruct (262k context) |
| 67 | +- `qwen/qwen3-32b` - Qwen3 32B (reasoning, tools) |
| 68 | + |
| 69 | +## Features |
| 70 | + |
| 71 | +- ✅ Streaming chat completions |
| 72 | +- ✅ Structured output (JSON Schema) |
| 73 | +- ✅ Function/tool calling |
| 74 | +- ✅ Multimodal input (text + images for vision models) |
| 75 | +- ❌ Embeddings (not supported by Groq) |
| 76 | +- ❌ Image generation (not supported by Groq) |
| 77 | + |
| 78 | +## Tree-Shakeable Adapters |
| 79 | + |
| 80 | +This package uses tree-shakeable adapters, so you only import what you need: |
| 81 | + |
| 82 | +```typescript |
| 83 | +// Only imports text adapter |
| 84 | +import { groqText } from '@tanstack/ai-groq' |
| 85 | +``` |
| 86 | + |
| 87 | +This keeps your bundle size small! |
| 88 | + |
| 89 | +## License |
| 90 | + |
| 91 | +MIT |
0 commit comments