Skip to content

Conversation

@princeaden1
Copy link

Summary

This PR introduces an example for using image inputs with the Anthropic client. It enables multimodal functionality where the model can understand and respond to image-based prompts alongside text.

Changes

  • Extended client to accept image files as input (e.g., via fs.createReadStream)
  • Added example usage in examples/images.ts demonstrating how to send an image prompt

Usage

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,
  }); ```

@princeaden1 princeaden1 requested a review from a team as a code owner July 23, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant