A complete, working C++ chat application using the OpenRouter API. This is your starting point for the AI++ 101 workshop.
- C++20 compiler (GCC 13+ or Clang 17+)
- CMake 3.27+
- Ninja build system (make requires changing presets)
- OpenSSL development libraries
- ccache (optional, for faster rebuilds)
-
Copy
.env.exampleto.envand add your OpenRouter API key:cp .env.example .env # Edit .env and set OPENROUTER_API_KEY=sk-or-v1-your-key-here -
Build:
cmake --preset debug cmake --build --preset debug
NOTE: 'debug' is an alias for 'debug-clang'. See CMakePresets.json for other available presets, or add your own.
-
Run tests:
ctest --preset debug
-
Run the chat app:
.build/debug-clang/src/wjh/apps/chat/chat_app
-m, --model <id> Model ID (default: anthropic/claude-sonnet-4)
-s, --system-prompt <text> System prompt
-t, --max-tokens <n> Max response tokens (default: 4096)
--show-config Display resolved config and exit
-h, --help Show help
/exit,/quit- Exit the chat/clear- Clear conversation history/help- Show available commands
| Preset | Compiler | Build Type | ASan |
|---|---|---|---|
debug |
Clang | Debug | ON |
release |
Clang | Release | ON |
debug-gcc |
GCC | Debug | OFF |
debug-clang |
Clang | Debug | ON |
release-gcc |
GCC | Release | OFF |
release-clang |
Clang | Release | ON |
./scripts/verify-all.sh # Debug builds (gcc + clang)
./scripts/verify-all.sh --all # All variantsstarter/
├── src/wjh/
│ ├── chat/ # Core chat library
│ │ ├── types.atlas # Strong type definitions
│ │ ├── Result.hpp # Error handling
│ │ ├── Config.hpp/cpp # Configuration resolution
│ │ ├── CommandLine.hpp/cpp # CLI argument parsing
│ │ ├── ChatLoop.hpp/cpp # Main chat loop
│ │ ├── client/ # HTTP + OpenRouter client
│ │ ├── conversation/ # Message + Conversation
│ │ └── tests/ # Unit tests
│ ├── apps/chat/ # Executable
│ └── testing/ # Test utilities (MockClient)
└── cmake/ # Build modules
Settings are resolved in this order (highest to lowest precedence):
- Command-line arguments
.env.local(gitignored).env(project config)~/.config/aipp101_chat/.env(user preferences)- Built-in defaults
| Variable | Required | Default | Description |
|---|---|---|---|
OPENROUTER_API_KEY |
Yes | - | Your OpenRouter API key |
LLM_MODEL |
No | anthropic/claude-sonnet-4 |
Model identifier |
MAX_TOKENS |
No | 4096 |
Maximum response tokens |
SYSTEM_PROMPT |
No | - | System prompt text |