NeuralPlus 0.2.0
A small C++17 SDK for AI clients, sessions, tools, and tracing
Loading...
Searching...
No Matches
anthropic_multimodal.cpp

Send image and PDF inputs through the real Anthropic client.

// Copyright 2026 Aniket Kulkarni
// SPDX-License-Identifier: Apache-2.0
#include "example_support.hpp"
#include <iostream>
#include <utility>
using namespace neuralplus;
using namespace neuralplus_examples;
namespace {
void usage() {
std::cout
<< "Claude image/PDF input using the real Messages API\n"
<< "Usage: neuralplus_anthropic_multimodal [options]\n"
<< " --image PATH Add an inline image\n"
<< " --pdf PATH Add an inline PDF\n"
<< " --api-key KEY Override ANTHROPIC_API_KEY\n"
<< " --model ID Override claude-sonnet-5\n"
<< " --prompt TEXT Question about the supplied media\n"
<< " --help Show this message\n";
}
} // namespace
int main(int argc, const char* const* argv) {
try {
const Arguments arguments(
argc,
argv,
{"--image", "--pdf", "--api-key", "--model", "--prompt"});
if (arguments.help()) {
usage();
return 0;
}
if (!arguments.has("--image") && !arguments.has("--pdf")) {
throw std::invalid_argument(
"provide --image PATH, --pdf PATH, or both");
}
AnthropicConfig config =
arguments.has("--model")
? AnthropicConfig(arguments.require("--model"))
: models::anthropic::claude_sonnet_5();
config.model.capabilities.text_input = true;
arguments.has("--image");
arguments.has("--pdf");
apply_api_key(arguments, config.api_key);
contents.push_back(Content::text(arguments.value_or(
"--prompt", "Describe and summarize the supplied content.")));
if (arguments.has("--image")) {
const std::string path = arguments.require("--image");
contents.push_back(
Content::image_bytes(read_bytes(path), media_type(path)));
}
if (arguments.has("--pdf")) {
const std::string path = arguments.require("--pdf");
contents.push_back(Content::file_bytes(
read_bytes(path), "application/pdf", filename(path)));
}
auto client = make_client(std::move(config));
const AIResponse response =
client->generate(Message::user(std::move(contents)));
std::cout << response.message.text() << '\n';
return 0;
} catch (const std::exception& error) {
return print_exception(error);
}
}
std::string text() const
Concatenates text parts without discarding non-text parts from the message.
std::vector< Content > Contents
Ordered content-part collection used by multimodal messages.
Definition types.hpp:211
NEURALPLUS_API AnthropicConfig claude_sonnet_5()
NEURALPLUS_API std::unique_ptr< AIClient > make_client(OpenAIConfig config, const ClientOptions &options={})
Creates an OpenAI client. Credentials resolve as explicit value, environment, error.
Normalized response returned by both one provider round and the full tool loop.
Definition types.hpp:393
Message message
Assistant message returned by the provider.
Definition types.hpp:398
Definition providers.hpp:50
ModelDescriptor model
Model ID, capabilities, limits, and data-driven provider options.
Definition providers.hpp:55
std::optional< std::string > api_key
Explicit API key. When empty, ANTHROPIC_API_KEY is read once.
Definition providers.hpp:58
Model features used for early validation and feature discovery.
Definition types.hpp:282
bool file_input
Accepts at least one supported file source.
Definition types.hpp:302
bool text_input
Accepts UTF-8 text input.
Definition types.hpp:284
bool image_input
Accepts at least one supported image source.
Definition types.hpp:290
bool text_output
Can return normalized text.
Definition types.hpp:287
ModelCapabilities capabilities
Discoverable features used for early validation.
Definition types.hpp:326