anthropics / anthropic-sdk-typescript

Access to Anthropic's safety-first language model APIs
https://www.npmjs.com/package/@anthropic-ai/sdk
MIT License
711 stars 78 forks source link

Binary support #337

Closed philkunz closed 5 months ago

philkunz commented 7 months ago

From the docs it is not clear how we are supposed to input binaries and images...

philkunz commented 7 months ago

Whats the status on this one?

atali commented 7 months ago

would love to see a code example, trying multiple solutions but none of them worked

mixa9269 commented 6 months ago

Try this one:

const message = await anthropic.messages.create({
    max_tokens: 1024,
    model: 'claude-3-haiku-20240307',
    messages: [{ 
      role: 'user', 
      content: [
        {
          type: 'image',
          source: {
            data: base64,
            media_type: 'image/jpeg',
            type: 'base64',
          }
        },
        {
          type: 'text',
          text: 'Your instruction here',
        },
      ],
    }],
  });
olu-an commented 5 months ago

@philkunz @atali we have documentation with examples for image use cases: https://docs.anthropic.com/en/docs/vision.

Could you reopen with more details if you still have questions?