Build a conversation out of system, user, and assistant messages, then call OpenAI's Chat Completions API and see the model's reply — with the API key kept safely server-side.
Chat model via OpenAI's /v1/chat/completions endpoint, called
through a Netlify Function that hides the API key. You control the
messages (each with a system,
user, or assistant role), the
model, the temperature, and the
max tokens. The function validates and clamps every field
server-side, so the endpoint can only run this demo.
Source on GitHub.