JavaScript SDK API
TaxiaClient methods, options, streaming, batch dedupe, and error handling.
TaxiaClient
import { TaxiaClient } from '@xaikorea0/js-client';
const client = new TaxiaClient({
apiKey: 'YOUR_API_KEY',
cacheEnabled: true,
timeoutMs: 10000,
retry: { retries: 2, baseDelayMs: 500 },
});
Methods
- query(question: string): Promise<QueryResponse>
- queryBatch(questions: string[]): Promise<QueryResponse[]>
- queryStream(question: string, onChunk: (chunk: string) => void): Promise<void>
QueryResponse
- answer: string
- citations: { law_name: string; article_number: string; content?: string }[]
- trace_id?: string
Options
- apiKey (required)
- baseUrl (optional)
- cacheEnabled (default true, TTL 1h)
- timeoutMs
- retry.retries (5xx)
- retry.baseDelayMs
Error handling
import { HttpError } from '@xaikorea0/js-client/utils/http';
try {
await client.query('...');
} catch (err) {
if (err instanceof HttpError) {
console.error('status', err.status);
}
}
Streaming (SSE)
- text/event-stream; longer timeout than normal queries
- throws HttpError on server errors
Batch deduplication
Duplicate questions in the same batch execute once and share the result.
Utilities
HuggingFaceDataLoader
import { HuggingFaceDataLoader } from '@xaikorea0/js-client/utils/hf-loader';
const loader = new HuggingFaceDataLoader();
const data = await loader.downloadDataNode();
- Browser: checkForUpdatesBrowser() with ETag + IndexedDB
- Node: downloadDataNode() streams and caches locally
Links
- Quick start: js/quickstart
- React: js/react
- Vue: js/vue
- Next.js: js/next
- HF loader: js/hf-loader
- FAQ: js/faq
- npm: @xaikorea0/js-client
- GitHub: src/js