19 lines
715 B
JavaScript
19 lines
715 B
JavaScript
import Anthropic from '@anthropic-ai/sdk'
|
|
|
|
const MISSING_CREDENTIALS = [
|
|
'No API credentials found.',
|
|
'Set ANTHROPIC_API_KEY, or log in once with `ant auth login`.',
|
|
'Use --dry-run to read the .odt files without calling the model.'
|
|
].join('\n')
|
|
|
|
// The SDK resolves credentials on its own (ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN
|
|
// or an `ant auth login` profile), so we never read them ourselves. It only
|
|
// reports a missing one when a request is sent - `verifyApiAccess` does that
|
|
// check up front.
|
|
export function createAnthropicClient() {
|
|
try {
|
|
return { ok: true, client: new Anthropic() }
|
|
} catch (error) {
|
|
return { ok: false, message: `${MISSING_CREDENTIALS}\n(${error.message})` }
|
|
}
|
|
}
|