Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/images.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env -S npm run tsn -T

import Anthropic from '@anthropic-ai/sdk';
import fs from 'fs';
import path from 'path';

const client = new Anthropic(); // gets API Key from environment variable ANTHROPIC_API_KEY
async function main() {
const filePath = path.join(__dirname, 'logo.png');
const buffer = fs.readFileSync(filePath);
const base64Image = buffer.toString('base64');
const result = await client.messages.create({
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'What is in this image?',
},
{
type: 'image',
source: {
data: base64Image,
type: 'base64',
media_type: 'image/png',
},
},
],
},
],
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
});
console.dir(result);
}

main();
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.