TypeScript SDK Quickstart
Prerequisites
- Node.js 18+ or a modern browser
- A FAOS API key (get one here)
Install
npm install @faos/sdk
Initialize
import { FaosClient } from '@faos/sdk';
const client = new FaosClient({
apiKey: process.env.FAOS_API_KEY ?? 'faos_sk_your_key_here',
});
Invoke an Agent
import { FaosClient } from '@faos/sdk';
const client = new FaosClient({ apiKey: 'faos_sk_your_key_here' });
// Basic invocation
const response = await client.agents.invoke(
'credit-risk-analyst',
{ query: 'Analyze Q1 2024 financial statements' },
);
console.log(response.result);
Typed Responses with Generics
import { FaosClient } from '@faos/sdk';
interface CreditAnalysis {
insights: string[];
riskScore: number;
recommendation: string;
}
const client = new FaosClient({ apiKey: 'faos_sk_your_key_here' });
const res = await client.agents.invoke<CreditAnalysis>(
'credit-risk-analyst',
{ query: 'Analyze Q1 2024' },
);
res.result.insights; // string[] — fully typed!
res.result.riskScore; // number
res.result.recommendation; // string
Streaming
import { FaosClient } from '@faos/sdk';
const client = new FaosClient({ apiKey: 'faos_sk_your_key_here' });
for await (const chunk of client.agents.stream(
'credit-risk-analyst',
{ query: 'Analyze Q1 2024' },
)) {
if (chunk.type === 'text') {
process.stdout.write(chunk.data);
}
}