openai-cpp  by olrea

C++ library for the OpenAI API

created 2 years ago
259 stars

Top 98.5% on sourcepulse

GitHubView on GitHub
Project Summary

This C++ library provides a lightweight, header-only interface to the OpenAI API, targeting C++ developers who need to integrate AI capabilities into their applications. It simplifies API interactions, offering convenient access to various OpenAI endpoints like completions, image generation, and embeddings.

How It Works

The library is designed to be header-only, requiring only two header files (or one if Nlohmann JSON is already included). It leverages libcurl for HTTP requests and Nlohmann JSON for request/response serialization. This approach minimizes build complexity and dependency management, allowing for easy integration into existing C++ projects.

Quick Start & Requirements

  • Install: Copy the include/openai directory into your project and include "openai.hpp".
  • Prerequisites: C++11/14/17/20 compatible compiler, libcurl development package.
  • Usage: Set the OPENAI_API_KEY environment variable or provide the key directly.
  • Examples: Available in the examples/ directory. Build with cmake .. && make.
  • Docs: API reference is implicitly covered by the example files.

Highlighted Details

  • Header-only design for easy integration.
  • Supports a comprehensive set of OpenAI API endpoints, including chat completions and audio transcription/translation.
  • Provides flexible error handling, with options to throw exceptions or display warnings.
  • Allows direct use of openai::post() and openai::get() for unsupported or new API methods.

Maintenance & Community

  • Community-maintained.
  • No explicit mention of active contributors, sponsorships, or community channels like Discord/Slack.

Licensing & Compatibility

  • License: MIT.
  • Compatibility: Permissive MIT license allows for commercial use and linking with closed-source projects.

Limitations & Caveats

The library is community-maintained, and while it aims to cover all OpenAI API features, newly released endpoints might not be immediately supported. Troubleshooting libcurl on Windows may require manual configuration.

Health Check
Last commit

1 year ago

Responsiveness

1 week

Pull Requests (30d)
1
Issues (30d)
0
Star History
24 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.