OpenEvidence SDK patterns and best practices for clinical AI integration.
Use when implementing advanced SDK features, optimizing API usage,
or following clinical decision support best practices.
Trigger with phrases like "openevidence patterns", "openevidence best practices",
"openevidence sdk", "clinical ai patterns".
Production-ready patterns for the OpenEvidence clinical evidence API. OpenEvidence provides REST endpoints for querying medical literature, retrieving clinical guidelines, and generating evidence-based recommendations. The API authenticates via OPENEVIDENCE_API_KEY and returns structured clinical data with citation provenance. A singleton client enforces consistent auth, handles healthcare-specific errors, and preserves citation chains for audit compliance.
Singleton Client
const OE_BASE = 'https://api.openevidence.com/v1';
let _client: OpenEvidenceClient | null = null;
export function getClient(): OpenEvidenceClient {
if (!_client) {
const apiKey = process.env.OPENEVIDENCE_API_KEY;
if (!apiKey) throw new Error('OPENEVIDENCE_API_KEY must be set — get it from openevidence.com/developer');
_client = new OpenEvidenceClient(apiKey);
}
return _client;
}
class OpenEvidenceClient {
private headers: Record<string, string>;
constructor(apiKey: string) { this.headers = { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }; }
async query(question: string, opts: { specialty?: string; maxResults?: number } = {}): Promise<EvidenceResponse> {
const res = await fetch(`${OE_BASE}/query`, { method: 'POST', headers: this.headers,
body: JSON.stringify({ question, specialty: opts.specialty, max_results: opts.maxResults ?? 10 }) });
if (!res.ok) throw new OEError(res.status, await res.text()); return res.json();
}
async getCitation(citationId: string): Promise<Citation> {
const res = await fetch(`${OE_BASE}/citations/${citationId}`, { headers: this.headers });
if (!res.ok) throw new OEError(res.status, await res.text()); return res.json();
}
}