22 lines
791 B
JavaScript
22 lines
791 B
JavaScript
import { MODEL_ID } from '#import-recipes/extraction/MODEL_ID.js'
|
|
|
|
const MISSING_CREDENTIALS = [
|
|
'Cannot reach the Claude API.',
|
|
'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')
|
|
|
|
// Pre-flight before the first recipe: counting tokens is free and needs the
|
|
// same credentials as the extraction call, so a missing key is reported before
|
|
// any file is read rather than once per file.
|
|
export async function verifyApiAccess(client) {
|
|
try {
|
|
await client.messages.countTokens({
|
|
model: MODEL_ID,
|
|
messages: [{ role: 'user', content: 'ping' }]
|
|
})
|
|
return { ok: true }
|
|
} catch (error) {
|
|
return { ok: false, message: `${MISSING_CREDENTIALS}\n(${error.message})` }
|
|
}
|
|
}
|