Skip to main content
A simplified wrapper around openai_chat_complete() for quick, single-turn chat interactions. Use this when you need a straightforward question-and-answer interaction without the complexity of managing message arrays.

Samples

Quick question

Get a response to a simple question:
SELECT ai.openai_chat_complete_simple('What is PostgreSQL?');

Specify a model

Use a different GPT model:
SELECT ai.openai_chat_complete_simple(
    'What is a hypertable?',
    model => 'gpt-4o'
);

Arguments

NameTypeDefaultRequiredDescription
messageTEXT-The user message/question
api_keyTEXTNULLOpenAI API key. If not provided, uses ai.openai_api_key setting
api_key_nameTEXTNULLName of the secret containing the API key
modelTEXT'gpt-4o-mini'The OpenAI model to use
client_configJSONBNULLAdvanced client configuration options

Returns

TEXT: The text response from the model.