Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main() {
int main() {
// Ensure ANTHROPIC_API_KEY environment variable is set
auto client = ai::anthropic::create_client();
ai::GenerateOptions options(ai::anthropic::models::kClaudeSonnet5,
ai::GenerateOptions options(ai::anthropic::models::kClaudeSonnet55,
"Explain quantum computing in simple terms.");
options.system = "You are a helpful assistant.";
auto result = client.generate_text(options);
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main() {

auto client4 = ai::anthropic::create_client();
ai::GenerateOptions options4;
options4.model = ai::anthropic::models::kClaudeSonnet5;
options4.model = ai::anthropic::models::kClaudeSonnet55;
options4.prompt =
"Write a haiku about programming. Just the haiku, nothing else.";

Expand Down
5 changes: 3 additions & 2 deletions examples/components/all/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ int main() {
try {
auto anthropic_client = ai::anthropic::create_client();
std::cout << "✓ Anthropic client created successfully\n";
std::cout << "✓ Available models: " << ai::anthropic::models::kClaudeSonnet5
<< ", " << ai::anthropic::models::kClaudeHaiku45 << "\n";
std::cout << "✓ Available models: "
<< ai::anthropic::models::kClaudeSonnet55 << ", "
<< ai::anthropic::models::kClaudeHaiku55 << "\n";
} catch (const std::exception& e) {
std::cout << "✗ Anthropic client failed: " << e.what() << "\n";
}
Expand Down
4 changes: 2 additions & 2 deletions examples/test_anthropic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main() {
// Test simple generation
std::cout << "Testing Anthropic text generation...\n\n";

ai::GenerateOptions options(ai::anthropic::models::kClaudeHaiku45,
ai::GenerateOptions options(ai::anthropic::models::kClaudeHaiku55,
"You are a helpful assistant.",
"Why is the sky blue? Give a short answer.");

Expand All @@ -35,7 +35,7 @@ int main() {
std::cout << "\nTesting streaming...\n";

ai::GenerateOptions stream_opts(
ai::anthropic::models::kClaudeHaiku45,
ai::anthropic::models::kClaudeHaiku55,
"Count from 1 to 5 slowly and with each number say 'tick'");
ai::StreamOptions stream_options(stream_opts);

Expand Down
2 changes: 1 addition & 1 deletion examples/tool_calling_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ int main() {
start_time = std::chrono::high_resolution_clock::now();

ai::GenerateOptions anthropic_options;
anthropic_options.model = ai::anthropic::models::kClaudeSonnet5;
anthropic_options.model = ai::anthropic::models::kClaudeSonnet55;
anthropic_options.prompt = R"(
Please help me with these THREE tasks. You MUST use the tools to complete ALL of them:
1. Use the fetch_news tool to get tech news articles
Expand Down
14 changes: 13 additions & 1 deletion include/ai/anthropic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ namespace anthropic {

namespace models {
/// Current Anthropic model identifiers
///
/// Claude Fable 5.1 and later, Claude Opus 5.5 and Claude Sonnet 5.5 reject a
/// forced tool choice (`ToolChoice::required()` and `ToolChoice::specific()`)
/// with HTTP 400; use `ToolChoice::auto_choice()` and name the tool in the
/// prompt instead.
constexpr const char* kClaudeFable52 = "claude-fable-5-2";
constexpr const char* kClaudeOpus55 = "claude-opus-5-5";
constexpr const char* kClaudeSonnet55 = "claude-sonnet-5-5";
constexpr const char* kClaudeHaiku55 = "claude-haiku-5-5";

/// Previous-generation model identifiers (still available)
constexpr const char* kClaudeFable51 = "claude-fable-5-1";
constexpr const char* kClaudeFable5 = "claude-fable-5";
constexpr const char* kClaudeOpus5 = "claude-opus-5";
constexpr const char* kClaudeOpus48 = "claude-opus-4-8";
Expand All @@ -39,7 +51,7 @@ constexpr const char* kClaudeOpus41 =
constexpr const char* kClaudeOpus41Snapshot = "claude-opus-4-1-20250805";

/// Default model used when none is specified
constexpr const char* kDefaultModel = kClaudeSonnet5;
constexpr const char* kDefaultModel = kClaudeSonnet55;
} // namespace models

/// Create an Anthropic client with default configuration
Expand Down
22 changes: 16 additions & 6 deletions include/ai/openai.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,42 @@ namespace openai {
namespace models {
/// Common OpenAI model identifiers

// GPT-5.6 series (current frontier family)
// GPT-6 series (current frontier family). On Chat Completions, which this
// SDK uses, these models reject sampling parameters and do not support tool
// calling (OpenAI serves their tool calling through the Responses API only).
constexpr const char* kGpt62Astra = "gpt-6.2-astra";
constexpr const char* kGpt62Sol = "gpt-6.2-sol";
constexpr const char* kGpt61Terra = "gpt-6.1-terra";
constexpr const char* kGpt6Luna = "gpt-6-luna";

// GPT-5.6 series (latest family with tool calling on Chat Completions)
constexpr const char* kGpt56 = "gpt-5.6"; // Alias for GPT-5.6 Sol
constexpr const char* kGpt56Sol = "gpt-5.6-sol";
constexpr const char* kGpt56Terra = "gpt-5.6-terra";
constexpr const char* kGpt56Luna = "gpt-5.6-luna";

// Earlier current GPT-5 series
// Earlier GPT-5 series
constexpr const char* kGpt55 = "gpt-5.5";
constexpr const char* kGpt54 = "gpt-5.4";
constexpr const char* kGpt54Pro = "gpt-5.4-pro";
constexpr const char* kGpt54Mini = "gpt-5.4-mini";
constexpr const char* kGpt54Nano = "gpt-5.4-nano";
constexpr const char* kGpt54Nano = "gpt-5.4-nano"; // Shutdown: 2027-04-01

// GPT-5 small variants (current)
// GPT-5 small variants (deprecated, shutdown: 2026-12-11; use kGpt61Terra
// and kGpt6Luna)
constexpr const char* kGpt5Mini = "gpt-5-mini";
constexpr const char* kGpt5Nano = "gpt-5-nano";

// GPT-4.1 series (still current non-reasoning leaders)
// GPT-4.1 series (deprecated, shutdown: 2027-01-14; use kGpt6Luna)
constexpr const char* kGpt41 = "gpt-4.1";
constexpr const char* kGpt41Mini = "gpt-4.1-mini";

// Embeddings
constexpr const char* kTextEmbedding3Small = "text-embedding-3-small";
constexpr const char* kTextEmbedding3Large = "text-embedding-3-large";

/// Default model used when none is specified
/// Default model used when none is specified. It stays on GPT-5.6 because the
/// GPT-6 series does not support tool calling on Chat Completions.
constexpr const char* kDefaultModel = kGpt56;

} // namespace models
Expand Down
18 changes: 10 additions & 8 deletions src/providers/anthropic/anthropic_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ std::vector<std::string> AnthropicClient::supported_models() const {
// snapshot variants (e.g. "claude-sonnet-4-5-20250929") are accepted by the
// Anthropic API; list both so identifiers in `ai::anthropic::models::*`
// resolve via `supports_model()`.
return {models::kClaudeFable5, models::kClaudeOpus5,
models::kClaudeOpus48, models::kClaudeSonnet5,
models::kClaudeOpus47, models::kClaudeSonnet46,
models::kClaudeOpus46, models::kClaudeHaiku45,
models::kClaudeHaiku45Snapshot, models::kClaudeOpus45,
models::kClaudeOpus45Snapshot, models::kClaudeSonnet45,
models::kClaudeSonnet45Snapshot, models::kClaudeOpus41,
models::kClaudeOpus41Snapshot};
return {models::kClaudeFable52, models::kClaudeOpus55,
models::kClaudeSonnet55, models::kClaudeHaiku55,
models::kClaudeFable51, models::kClaudeFable5,
models::kClaudeOpus5, models::kClaudeOpus48,
models::kClaudeSonnet5, models::kClaudeOpus47,
models::kClaudeSonnet46, models::kClaudeOpus46,
models::kClaudeHaiku45, models::kClaudeHaiku45Snapshot,
models::kClaudeOpus45, models::kClaudeOpus45Snapshot,
models::kClaudeSonnet45, models::kClaudeSonnet45Snapshot,
models::kClaudeOpus41, models::kClaudeOpus41Snapshot};
}

bool AnthropicClient::supports_model(const std::string& model_name) const {
Expand Down
8 changes: 5 additions & 3 deletions src/providers/anthropic/anthropic_request_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ nlohmann::json AnthropicRequestBuilder::build_request_json(
// Add optional parameters
// Recent Anthropic models reject sampling controls. Keep accepting the
// provider-neutral options while omitting them for those model IDs.
constexpr std::array<const char*, 5> kSamplingRejectingModelPrefixes = {
models::kClaudeOpus5, models::kClaudeOpus48, models::kClaudeOpus47,
models::kClaudeFable5, models::kClaudeSonnet5};
// The prefixes also cover the later point releases ("claude-opus-5-5",
// "claude-fable-5-2", "claude-sonnet-5-5", ...).
constexpr std::array<const char*, 6> kSamplingRejectingModelPrefixes = {
models::kClaudeOpus5, models::kClaudeOpus48, models::kClaudeOpus47,
models::kClaudeFable5, models::kClaudeSonnet5, models::kClaudeHaiku55};
const bool rejects_sampling_parameters = std::any_of(
kSamplingRejectingModelPrefixes.begin(),
kSamplingRejectingModelPrefixes.end(), [&options](const char* prefix) {
Expand Down
5 changes: 5 additions & 0 deletions src/providers/anthropic/anthropic_response_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ FinishReason AnthropicResponseParser::parse_stop_reason(
if (reason == "tool_use") {
return kFinishReasonToolCalls;
}
if (reason == "refusal") {
// Safety classifiers declined the request (HTTP 200, details in
// `stop_details`).
return kFinishReasonContentFilter;
}
return kFinishReasonStop;
}

Expand Down
2 changes: 2 additions & 0 deletions src/providers/anthropic/anthropic_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ void AnthropicStreamImpl::process_sse_event(const std::string& data) {
finish_reason_ = kFinishReasonLength;
} else if (stop_reason == "tool_use") {
finish_reason_ = kFinishReasonToolCalls;
} else if (stop_reason == "refusal") {
finish_reason_ = kFinishReasonContentFilter;
} else if (!stop_reason.empty()) {
finish_reason_ = kFinishReasonStop;
}
Expand Down
7 changes: 5 additions & 2 deletions src/providers/openai/openai_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ std::string OpenAIClient::provider_name() const {
}

std::vector<std::string> OpenAIClient::supported_models() const {
return {// Current GPT-5 series
return {// GPT-6 series
models::kGpt62Astra, models::kGpt62Sol, models::kGpt61Terra,
models::kGpt6Luna,
// GPT-5 series
models::kGpt56, models::kGpt56Sol, models::kGpt56Terra,
models::kGpt56Luna, models::kGpt55, models::kGpt54, models::kGpt54Pro,
models::kGpt54Mini, models::kGpt54Nano, models::kGpt5Mini,
models::kGpt5Nano,
// Current GPT-4.1 series
// GPT-4.1 series
models::kGpt41, models::kGpt41Mini};
}

Expand Down
29 changes: 22 additions & 7 deletions src/providers/openai/openai_request_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@ namespace openai {

namespace {

// The lowest `reasoning_effort` a GPT-5 family model accepts on Chat
// The lowest `reasoning_effort` a GPT-5 or GPT-6 family model accepts on Chat
// Completions, or nullopt when the parameter must be left out: the model is
// not in the family, or it is a variant whose accepted values are fixed or
// not known. An unsupported value fails the request with HTTP 400, so the
// field is only sent where the value is known to be accepted.
std::optional<std::string_view> lowest_reasoning_effort(
std::string_view model) {
if (model.starts_with("gpt-6")) {
// The pro and cyber variants have value sets of their own.
for (const std::string_view variant : {"-pro", "-cyber"}) {
if (model.find(variant) != std::string_view::npos) {
return std::nullopt;
}
}
// Every GPT-6 model accepts "low"; GPT-6.2 and later reject "none", which
// only GPT-6 Luna and GPT-6.1 Terra are documented to accept.
if (model.starts_with("gpt-6-luna") || model.starts_with("gpt-6.1-terra")) {
return "none";
}
return "low";
}

if (!model.starts_with("gpt-5")) {
return std::nullopt;
}
Expand Down Expand Up @@ -141,13 +156,13 @@ nlohmann::json OpenAIRequestBuilder::build_request_json(
}

// Add optional parameters
// The GPT-5 family is reasoning-first on Chat Completions: it rejects
// sampling controls ("'temperature' does not support 0.0 with this model.
// Only the default (1) value is supported."). Keep accepting the
// The GPT-5 and GPT-6 families are reasoning-first on Chat Completions: they
// reject sampling controls ("'temperature' does not support 0.0 with this
// model. Only the default (1) value is supported."). Keep accepting the
// provider-neutral options while omitting them for those model IDs,
// mirroring the Anthropic builder.
const bool is_gpt5_family = options.model.starts_with("gpt-5");
const bool rejects_sampling_parameters = is_gpt5_family;
const bool rejects_sampling_parameters =
options.model.starts_with("gpt-5") || options.model.starts_with("gpt-6");
const auto add_sampling_parameter = [&](const char* key,
const std::optional<double>& value) {
if (!value) {
Expand Down Expand Up @@ -181,7 +196,7 @@ nlohmann::json OpenAIRequestBuilder::build_request_json(
request["seed"] = *options.seed;
}

// Much of the GPT-5 family defaults to reasoning in Chat Completions. That
// The GPT-5 and GPT-6 families default to reasoning in Chat Completions. That
// mode can consume the full completion budget on hidden reasoning without
// producing user-visible text (acute with a small max_tokens), and on
// GPT-5.6 it does not support function tools. The unified SDK currently
Expand Down
9 changes: 5 additions & 4 deletions src/providers/openai/openai_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ void OpenAIStreamImpl::process_sse_line(std::string_view line) {

if (delta.contains("reasoning_content") &&
!delta["reasoning_content"].is_null()) {

std::string content = delta["reasoning_content"].get<std::string>();
ai::logger::log_debug("Received reasoning_content chunk - length: {}",
content.length());
//TODO: currently not passing content, needs revamping of StreamEvent constructor
push_event(StreamEvent(StreamEventType::kStreamEventTypeReasoningDelta));
}
// TODO: currently not passing content, needs revamping of StreamEvent
// constructor
push_event(
StreamEvent(StreamEventType::kStreamEventTypeReasoningDelta));
}

if (delta.contains("tool_calls") && delta["tool_calls"].is_array()) {
for (const auto& fragment : delta["tool_calls"]) {
Expand Down
19 changes: 11 additions & 8 deletions tests/integration/anthropic_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ TEST_F(AnthropicIntegrationTest, DifferentModelSupport) {

std::vector<std::string> models_to_test = {
ai::anthropic::models::kDefaultModel,
ai::anthropic::models::kClaudeOpus55,
ai::anthropic::models::kClaudeHaiku55,
ai::anthropic::models::kClaudeHaiku45};

for (const auto& model : models_to_test) {
Expand Down Expand Up @@ -278,7 +280,7 @@ TEST_F(AnthropicIntegrationTest, LargePromptHandling) {
auto large_prompt =
TestDataGenerator::createLargePrompt(2000); // ~2KB prompt

GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, large_prompt);
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, large_prompt);
auto result = client_->generate_text(options);

TestAssertions::assertSuccess(result);
Expand All @@ -299,7 +301,7 @@ TEST_F(AnthropicIntegrationTest, CustomBaseUrl) {
auto custom_client =
ai::anthropic::create_client(api_key, "https://api.anthropic.com");

GenerateOptions options(ai::anthropic::models::kClaudeSonnet5,
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55,
"Test custom base URL");
auto result = custom_client.generate_text(options);

Expand All @@ -313,7 +315,7 @@ TEST_F(AnthropicIntegrationTest, EmptyPrompt) {
GTEST_SKIP() << "No ANTHROPIC_API_KEY environment variable set";
}

GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, "");
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55, "");

// Empty prompt should be caught by validation
EXPECT_FALSE(options.is_valid());
Expand All @@ -328,7 +330,7 @@ TEST_F(AnthropicIntegrationTest, VeryLongResponse) {
GTEST_SKIP() << "No ANTHROPIC_API_KEY environment variable set";
}

GenerateOptions options(ai::anthropic::models::kClaudeSonnet5,
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55,
"Write a detailed explanation of quantum physics");
options.max_tokens = 500; // Reasonable limit for testing

Expand All @@ -349,7 +351,8 @@ TEST_F(AnthropicIntegrationTest, NetworkTimeout) {

// Note: This test documents timeout behavior but cannot reliably trigger it
// with the real API under normal conditions
GenerateOptions options(ai::anthropic::models::kClaudeSonnet5, "Simple test");
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55,
"Simple test");
auto result = client_->generate_text(options);

// Under normal conditions, this should succeed
Expand All @@ -374,7 +377,7 @@ TEST_F(AnthropicIntegrationTest, NetworkFailure) {
auto failing_client = ai::anthropic::create_client(
api_key, "http://localhost:59999"); // Very unlikely port to be in use

GenerateOptions options(ai::anthropic::models::kClaudeSonnet5,
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55,
"Test network failure");
auto result = failing_client.generate_text(options);

Expand Down Expand Up @@ -425,7 +428,7 @@ TEST_F(AnthropicIntegrationTest, MaxTokensRequired) {
GTEST_SKIP() << "No ANTHROPIC_API_KEY environment variable set";
}

GenerateOptions options(ai::anthropic::models::kClaudeSonnet5,
GenerateOptions options(ai::anthropic::models::kClaudeSonnet55,
"Tell me about artificial intelligence");
// Anthropic requires max_tokens to be set
options.max_tokens = 100;
Expand All @@ -444,7 +447,7 @@ TEST_F(AnthropicIntegrationTest, SystemMessageHandling) {

// Anthropic has specific handling for system messages
GenerateOptions options(
ai::anthropic::models::kClaudeSonnet5,
ai::anthropic::models::kClaudeSonnet55,
"You are Claude, an AI assistant created by Anthropic.",
"What is your name?");
options.max_tokens = 50;
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/openai_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ TEST_F(OpenAIIntegrationTest, DifferentModelSupport) {
GTEST_SKIP() << "No OPENAI_API_KEY environment variable set";
}

std::vector<std::string> models_to_test = {ai::openai::models::kGpt56,
ai::openai::models::kGpt56Luna};
std::vector<std::string> models_to_test = {
ai::openai::models::kGpt56, ai::openai::models::kGpt56Luna,
ai::openai::models::kGpt62Sol, ai::openai::models::kGpt6Luna};

for (const auto& model : models_to_test) {
if (!client_->supports_model(model)) {
Expand Down
Loading
Loading