mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 15:01:24 +00:00
docs(ai): Add browser usage section to README
- Document browser support and API key requirements - Add security warning about exposing keys in frontend - Keep documentation concise and practical
This commit is contained in:
parent
14d93ca8c6
commit
32bede3352
2 changed files with 104 additions and 85 deletions
|
|
@ -427,6 +427,25 @@ if (model) {
|
|||
}
|
||||
```
|
||||
|
||||
## Browser Usage
|
||||
|
||||
The library supports browser environments. You must pass the API key explicitly since environment variables are not available in browsers:
|
||||
|
||||
```typescript
|
||||
import { createLLM } from '@mariozechner/pi-ai';
|
||||
|
||||
// API key must be passed explicitly in browser
|
||||
const llm = createLLM('anthropic', 'claude-3-5-haiku-20241022', {
|
||||
apiKey: 'your-api-key'
|
||||
});
|
||||
|
||||
const response = await llm.generate({
|
||||
messages: [{ role: 'user', content: 'Hello!' }]
|
||||
});
|
||||
```
|
||||
|
||||
> **Security Warning**: Exposing API keys in frontend code is dangerous. Anyone can extract and abuse your keys. Only use this approach for internal tools or demos. For production applications, use a backend proxy that keeps your API keys secure.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Set these environment variables to use `createLLM` without passing API keys:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue