NeuralPlus 0.2.0
An open-source, provider-independent C++17 AI SDK and LLM client library
Loading...
Searching...
No Matches
NeuralPlus

NeuralPlus

C++17 GitHub repository CI Documentation License

NeuralPlus — an open-source C++17 AI SDK and LLM client library.

NeuralPlus is an open-source, provider-independent C++17 AI SDK and LLM client library for OpenAI, Anthropic, Gemini, tool calling, session state, and tracing.

Status: General Availability. Version 0.2.0 is the first supported release of the simplified NeuralPlus API.

The design in five pieces

  • AIClient owns the complete conversation/tool loop.
  • OpenAIClient, AnthropicClient, GeminiClient, and OpenAICompatibleClient translate one provider round.
  • Session owns conversation messages plus a thread-safe, process-local cache.
  • Tool is the formal executable extension point; FunctionTool covers most applications without a new subclass.
  • Any number of Tracer objects can be attached to a client. Built-ins cover console, JSON Lines files, memory, callbacks, and POSIX syslog.

A model name is data (ModelDescriptor::id), not a new C++ type. This keeps the class tree stable when providers add models. Typed configurations for common current models provide readable defaults without restricting custom model IDs.

Build

Prerequisites are CMake 3.20+, a C++17 compiler, libcurl development files, and Threads. CMake first looks for nlohmann/json 3.12.0 and otherwise downloads its checksum-pinned release archive.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev

The dev and release build presets build the library, tests, and all examples. To build only the examples, use the matching examples preset:

cmake --build --preset dev-examples
# Or: cmake --build --preset release-examples

Example executables are placed in build/dev/examples/ or build/release/examples/.

The equivalent generator-independent commands are documented in Getting started.

OpenAI client example

The factory returns the common AIClient interface. The OpenAI configuration reads OPENAI_API_KEY when config.api_key is not set:

#include <iostream>
#include <utility>
int main() {
auto client = neuralplus::make_client(std::move(config));
const auto response =
client->generate(session, "Explain RAII in one sentence.");
std::cout << response.message.text() << '\n';
}
Definition session.hpp:106
NEURALPLUS_API OpenAIConfig gpt_5_6_terra()

Change only the typed configuration passed to make_client to select another provider. The same Session, tools, and tracers work with every built-in provider. Credentials can also be assigned directly to the provider configuration; see Credentials.

The catalog includes current OpenAI, Anthropic, and Gemini configurations: Model configurations. An arbitrary provider model remains one typed configuration constructor away.

More LLM client examples

The built-in clients make real provider requests. They use ANTHROPIC_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY, and OPENAI_API_KEY when an explicit key is not assigned.

Anthropic conversation

auto client = neuralplus::make_client(std::move(config));
session.set_system("Answer as a concise C++ mentor.");
const auto response =
client->generate(session, "When should I use std::string_view?");
std::cout << response.message.text() << '\n';
void set_system(std::string message)
NEURALPLUS_API AnthropicConfig claude_sonnet_5()

Gemini conversation

auto client = neuralplus::make_client(std::move(config));
const auto response =
client->generate(session, "Give me three practical RAII examples.");
std::cout << response.message.text() << '\n';
NEURALPLUS_API GeminiConfig gemini_3_6_flash()

OpenAI-compatible server

Use the same interface with a local or hosted Chat Completions-compatible server:

"local-model", "http://localhost:8000/v1");
config.api_key_environment = "LOCAL_LLM_API_KEY"; // Optional.
auto client = neuralplus::make_client(std::move(config));
const auto response = client->generate("Explain move semantics simply.");
std::cout << response.message.text() << '\n';
Definition providers.hpp:96

Multimodal request

auto client = neuralplus::make_client(std::move(config));
contents.push_back(
neuralplus::Content::text("Describe the architecture in this image."));
contents.push_back(neuralplus::Content::image_url(
"https://example.com/architecture.png", "image/png"));
const auto response =
client->generate(neuralplus::Message::user(std::move(contents)));
std::cout << response.message.text() << '\n';
static Content text(std::string value)
Creates a UTF-8 text part.
static Content image_url(std::string url, std::string media_type={}, JsonValue options=JsonValue::object())
Creates an image referenced by URL.
static Message user(std::string text)
Creates a text user message.
std::vector< Content > Contents
Ordered content-part collection used by multimodal messages.
Definition types.hpp:211

Complete, runnable programs:

Scenario OpenAI Anthropic Gemini Compatible server
Chatbot source source source source
Custom model/config source source source source
Multimodal source source source source

Add a stateful tool and tracers

spec.name = "increment";
spec.description = "Increment this session's counter.";
spec.input_schema = {
{"type", "object"},
{"properties", {{"delta", {{"type", "integer"}}}}},
{"required", {"delta"}},
};
auto tool = std::make_shared<neuralplus::FunctionTool>(
std::move(spec),
const neuralplus::JsonValue& arguments) {
const int delta = arguments.at("delta").get<int>();
const int value = context.state().update<int>(
"counter", 0, [delta](int current) { return current + delta; });
return neuralplus::ToolOutput::json({{"counter", value}});
});
options.tools = {tool};
options.tracers = {
std::make_shared<neuralplus::ConsoleTracer>(),
std::make_shared<neuralplus::FileTracer>("trace.jsonl"),
};
Definition tool.hpp:28
SessionState & state() const noexcept
Returns the session-scoped state available to the tool.
Dependencies and behavior shared by all AIClient implementations.
Definition client.hpp:25
Tools tools
Immutable set of tools advertised to the configured model.
Definition client.hpp:27
static ToolOutput json(JsonValue value)
Creates a successful JSON result serialized as text content.
Description and JSON Schema advertised to a model.
Definition types.hpp:189
JsonValue input_schema
JSON Schema whose root type must be object.
Definition types.hpp:197
std::string name
Portable function name.
Definition types.hpp:191
std::string description
Human-readable instruction for deciding when to call the tool.
Definition types.hpp:194
nlohmann::json JsonValue
Definition types.hpp:26

Trace output is metadata-only by default. capture_trace_payloads makes payloads available to in-memory, callback, and custom tracers. FileTracer also requires FileTracerOptions::include_payloads; console and syslog output remain metadata-only. New trace files are created with mode 0600 on POSIX. Provider rounds, total tool calls, concurrent tool callbacks, and HTTP response sizes all have configurable bounds. Tool declarations are validated and snapshotted when the client is constructed.

The complete credential-free example uses FunctionAIClient: examples/simple_session.cpp. Ready-to-run chatbots, custom-model programs, and multimodal examples use the real built-in provider clients: Provider examples.

Documentation

Generate API documentation with:

cmake --preset docs
cmake --build --preset docs

The generated entry page is build/docs/api/index.html, and CI publishes the same output from main to GitHub Pages. See the Doxygen guide for installation, refresh, publishing, and non-preset commands.

Supported environments

The library targets C++17 on Linux, macOS, and Windows. Every CI run covers Ubuntu 22.04/24.04, macOS 14, Windows Server 2022, Rocky Linux 9, Debian 12, Red Hat UBI 9, Oracle Linux 9, and CentOS Stream 9. UBI is a compatibility signal for RHEL 9, not Red Hat certification. See Getting started for compiler and platform details.

License

NeuralPlus is licensed under the Apache License 2.0. Dependency attributions and licenses are recorded in THIRD_PARTY_NOTICES.md.