Introducing OpenAI C: A Lightweight C Client for OpenAI API
LunaStev

LunaStev @lunastev

About: Developer

Location:
Goyang, Republic of Korea
Joined:
Sep 11, 2024

Introducing OpenAI C: A Lightweight C Client for OpenAI API

Publish Date: Jun 6
1 0

Do you love C programming but feel left out from the AI boom?
Say hello to openai-c — a lightweight, dependency-minimal, MIT-licensed C client for the OpenAI Chat API.


✨ What is OpenAI C?

openai-c is a minimal wrapper around OpenAI’s Chat Completion API, written in pure C11. It lets you send prompts to models like gpt-3.5-turbo and get back responses — all without leaving your beloved C codebase.


🚀 Features

  • Written entirely in C (C11 standard)
  • Supports gpt-3.5-turbo and customizable model names
  • Simple API: openai_init(), openai_chat(), openai_cleanup()
  • Uses libcurl and cJSON
  • Lightweight and fast
  • MIT licensed

🧩 Basic Usage

#include <stdio.h>
#include "openai.h"

int main() {
    openai_init("your-api-key");

    char* res = openai_chat("Hello, who are you?");
    if (res) {
        printf("OpenAI says: %s\n", res);
        free(res);
    }

    openai_cleanup();
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

📦 Installation

git clone https://github.com/LunaStev/openai-c.git
cd openai-c
mkdir build && cd build
cmake ..
make
sudo make install
Enter fullscreen mode Exit fullscreen mode

📂 Folder Structure

openai-c/
├── include/        # openai.h
├── src/            # openai.c
├── examples/       # usage examples
├── CMakeLists.txt
└── LICENSE         # MIT License
Enter fullscreen mode Exit fullscreen mode

🔧 Dependencies


📜 License

MIT License – free to use, modify, and distribute.


🌎 GitHub

👉 Check it out: https://github.com/LunaStev/openai-c

Comments 0 total

    Add comment