Modern C++ LLM API client with openai-compatible support
| English - 简体中文 - 繁體中文 |
|---|
| Documentation - C++ API - C API - Examples |
Clean, type-safe LLM API client using C++23 modules. Fluent interface with zero-cost abstractions. Works with OpenAI, Poe, DeepSeek and compatible endpoints.
- C++23 Modules -
import mcpplibs.llmapi - Auto-Save History - Conversation history managed automatically
- Type-Safe Streaming - Concept-constrained callbacks
- Fluent Interface - Chainable methods
- Provider Agnostic - OpenAI, Poe, and compatible endpoints
import std;
import mcpplibs.llmapi;
int main() {
using namespace mcpplibs;
llmapi::Client client(std::getenv("OPENAI_API_KEY"), llmapi::URL::Poe);
client.model("gpt-5")
.system("You are a helpful assistant.")
.user("In one sentence, introduce modern C++. 并给出中文翻译")
.request([](std::string_view chunk) {
std::print("{}", chunk);
std::cout.flush();
});
return 0;
}llmapi::Client client(apiKey, llmapi::URL::OpenAI); // OpenAI
llmapi::Client client(apiKey, llmapi::URL::Poe); // Poe
llmapi::Client client(apiKey, llmapi::URL::DeepSeek); // Deepseek
llmapi::Client client(apiKey, "https://custom.com"); // Customxmake # Build
xmake run basic # Run example(after cofig OPENAI_API_KEY)-- 0 - Add mcpplibs's index repos
add_repositories("mcpplibs-index https://github.com/mcpplibs/llmapi.git")
-- 1 - Add the libraries and versions you need
add_requires("llmapi 0.0.2")More: mcpplibs-index
todo...
Apache-2.0 - see LICENSE