@ad-rian-studio/ai-client
v0.1.0
Published
Official TypeScript SDK helper for AD-RIAN Studio AI API
Downloads
220
Readme
AD-RIAN Studio AI Client
Official TypeScript SDK helper for interacting with the AD-RIAN Studio AI API.
Works in Node.js, Deno, Bun, modern browsers, Next.js, Cloudflare Workers, Vercel Edge functions, and React applications (@ai-sdk/react).
Installation
Install from npm:
# npm
npm install @ad-rian-studio/ai-client
# pnpm
pnpm add @ad-rian-studio/ai-client
# yarn
yarn add @ad-rian-studio/ai-client
# bun
bun add @ad-rian-studio/ai-clientThen import it in your code:
import { createClient } from '@ad-rian-studio/ai-client';Quick Start
1. Non-Streaming Request
import { createClient } from '@ad-rian-studio/ai-client';
const ai = createClient({
apiKey: process.env.CHAT_API_KEY, // optional for public endpoints
});
async function main() {
const response = await ai.sendMessage('Tell me about AD-RIAN Studio.');
console.log('Model:', response.model);
console.log('Answer:', response.text);
console.log('Tokens used:', response.usage);
}
main();2. Streaming Request
import { AdrianStudioAI } from '@ad-rian-studio/ai-client';
const ai = new AdrianStudioAI({ apiKey: process.env.CHAT_API_KEY });
async function streamResponse() {
const response = await ai.sendMessageStream('What projects are featured?');
// Response body contains the Vercel AI SDK UI message stream
const reader = response.body?.getReader();
const decoder = new TextDecoder();
while (reader) {
const { done, value } = await reader.read();
if (done) break;
console.log(decoder.decode(value));
}
}3. Vercel AI SDK & React Integration (@ai-sdk/react)
Use getChatTransport() to connect @ai-sdk/react's useChat directly:
import { useChat } from '@ai-sdk/react';
import { AdrianStudioAI } from '@ad-rian-studio/ai-client';
const ai = new AdrianStudioAI();
export function ChatComponent() {
const { messages, sendMessage } = useChat({
transport: ai.getChatTransport(),
body: {
variant: 'pro',
},
});
return (
<div>
{messages.map((m) => (
<div key={m.id}>
<strong>{m.role}:</strong>{' '}
{m.parts.map((p) => (p.type === 'text' ? p.text : '')).join('')}
</div>
))}
</div>
);
}4. Models, Providers & Mappings
The library exports the complete model registry and provider mappings used by AD-RIAN Studio:
import {
modelRegistry,
MODEL_PROVIDER_MAP,
PROVIDER_MODELS_MAP,
getModelById,
getModelsByProvider,
getModelsByCategory,
type ProviderString,
type ModelId,
type ModelCategory,
} from '@ad-rian-studio/ai-client';
// Look up model metadata by ID
const model = getModelById('google-gemini-flash');
console.log(model?.label, model?.provider, model?.supportsTools);
// Get all models for a specific provider
const openrouterModels = getModelsByProvider('openrouter');
// Get all models in the 'pro' variant category
const proModels = getModelsByCategory('pro');
// Quick lookup maps
const providerName = MODEL_PROVIDER_MAP['opencode-zen-deepseek-v4-flash']; // 'opencode-zen'Exported API
- Client:
AdrianStudioAI,AdrianStudioAPIError,createClient(),DEFAULT_BASE_URL,normalizeBaseURL(). - API Types:
ChatRequestBody,ChatTextResponse,ApiToolDefinition,ApiToolMap,ApiToolInputSchema,ApiToolError,AIError,AIResponse,AdrianStudioClientOptions,ChatOptions,UIMessage. - Models & Providers:
modelRegistry,MODEL_PROVIDER_MAP,PROVIDER_MODELS_MAP,getModelById(),getModelsByProvider(),getModelsByCategory(),ProviderString,ModelCategory,ModelRegistryEntry,ModelId,ModelString. - Tool Utilities:
isMasterTool(name),stripMasterPrefix(name),masterName(name),createToolError(msg, retryable). - Adapters:
createAdrianStudioTransport(options).
Error Handling
Non-2xx responses from the API throw an AdrianStudioAPIError:
import { AdrianStudioAPIError, createClient } from '@ad-rian-studio/ai-client';
const ai = createClient({ apiKey: process.env.CHAT_API_KEY });
try {
await ai.sendMessage('Hello!');
} catch (error) {
if (error instanceof AdrianStudioAPIError) {
console.error(`Request failed (${error.status}):`, error.message);
}
}Development
pnpm install— install dependenciespnpm typecheck— type check without emitting filespnpm build— build dual ESM/CommonJS output with TypeScript declarations indist/pnpm test— run offline unit tests via Vitestpnpm test:watch— run unit tests in interactive watch modepnpm test:live -- --api-key <YOUR_KEY>— run live integration tests against the live APIpnpm test:all— run all unit and live tests
License
MIT
