@piatrajs/ai
v0.2.0
Published
Thin wrapper over the OpenAI SDK, preset for the Piatra AI Gateway.
Maintainers
Readme
@piatrajs/ai
Thin wrapper over the official openai
SDK, preset for the Piatra AI Gateway. It does exactly
three things: presets the gateway base URL, reads the key from PIATRA_AI_KEY,
and exports typed piatra.* model-id constants. Everything else — chat,
streaming, retries — is the OpenAI SDK's, unchanged.
Install
npm install @piatrajs/aiUsage
import PiatraAI, { MODELS } from '@piatrajs/ai';
const client = new PiatraAI();
// apiKey defaults to process.env.PIATRA_AI_KEY
// baseURL defaults to https://ai.piatra.center/v1
const res = await client.chat.completions.create({
model: MODELS.GLM, // 'piatra.glm'
messages: [{ role: 'user', content: 'What is default logic?' }],
});Streaming and multimodal input are the OpenAI SDK's, unchanged:
const stream = await client.chat.completions.create({
model: MODELS.GLM,
messages,
stream: true,
});
for await (const chunk of stream) {
/* … */
}
await client.chat.completions.create({
model: MODELS.MEDGEMMA, // the vision-capable model
messages: [{
role: 'user',
content: [
{ type: 'text', text: 'describe this radiograph' },
{ type: 'image_url', image_url: { url: dataUrl } },
],
}],
});Configuration
| Option | Default | Notes |
| --------- | ---------------------------------- | --------------------------------------------------------------------- |
| apiKey | process.env.PIATRA_AI_KEY | The pi_live_* key, issued and owned by core. |
| baseURL | https://ai.piatra.center/v1 | Or set PIATRA_AI_BASE_URL. In-cluster callers use the internal DNS. |
Any other OpenAI client option is accepted and passed through unchanged.
