class ChatGPT::Client

Overview

Define the Client class that handles communication with the ChatGPT API

Defined in:

chatgpt/client.cr

Constant Summary

API_ENDPOINT = "https://api.openai.com"

Set the API endpoint URL (host only; path is given per-request)

WEB_APP_URL = "https://chat.openai.com"

ChatGPT Web App URL

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Initialize the Client object by building the required HTTP headers


[View source]

Instance Method Detail

def build_http_headers #

Build the required HTTP headers using the API key from environment variables


[View source]
def fetch_api_key #

Fetch the API key from the environment variables or display an error if not present


[View source]
def post_request(request_data : PostData) #

Send a POST request with the provided request data to the Responses API


[View source]
def send_chat_request(request_data : PostData) #

Send a model request to the OpenAI API (Responses API) and log the request and response data if in debug mode.


[View source]