OpenAI and Anthropic calls
Both rb.openai() and rb.anthropic() return native SDK instances. Catch errors the same way you would with the official SDKs:
import OpenAI from 'openai';
try {
const res = await rb.openai().chat.completions.create({ ... });
} catch (err) {
if (err instanceof OpenAI.APIError) {
console.error('API error:', err.status, err.message);
}
}
import Anthropic from '@anthropic-ai/sdk';
try {
const res = await rb.anthropic().messages.create({ ... });
} catch (err) {
if (err instanceof Anthropic.APIError) {
console.error('API error:', err.status, err.message);
}
}
Image generation
ImageResponse.json() checks the HTTP status for you. When a request fails, it throws with the error details:
try {
const result = await rb.image({
model: 'dall-e-3',
prompt: '', // Empty prompt triggers an error
}).json();
} catch (err) {
console.error('Image generation failed:', (err as Error).message);
// e.g. "prompt is required and must not be empty"
}
If you need to inspect the status code first:
const img = rb.image({ model: 'dall-e-3', prompt: '...' });
const status = await img.httpStatus();
if (status !== 200) {
console.warn('Unexpected status:', status);
}
const result = await img.json(); // Still throws on non-2xx
Rerank
Errors are thrown automatically — err.message will contain the upstream error description:
try {
const result = await rb.rerank({ ... });
} catch (err) {
console.error('Rerank failed:', (err as Error).message);
}