Skip to main content
Generate chat completions and receive the raw HTTP response. Use this when you need access to HTTP headers, status codes, or other low-level response details.

Arguments

NameTypeDefaultRequiredDescription
modelTEXT-The OpenAI model to use (e.g., gpt-4o, gpt-4o-mini, gpt-3.5-turbo)
messagesJSONB-Array of message objects with role and content fields
api_keyTEXTNULLOpenAI API key. If not provided, uses ai.openai_api_key setting
api_key_nameTEXTNULLName of the secret containing the API key
frequency_penaltyFLOATNULLPenalize new tokens based on their frequency (-2.0 to 2.0)
logit_biasJSONBNULLModify the likelihood of specified tokens appearing
logprobsBOOLEANNULLReturn log probabilities of output tokens
top_logprobsINTNULLNumber of most likely tokens to return at each position
max_tokensINTNULLMaximum number of tokens to generate
nINTNULLNumber of chat completion choices to generate
presence_penaltyFLOATNULLPenalize new tokens based on their presence (-2.0 to 2.0)
response_formatJSONBNULLFormat of the response (e.g., {"type": "json_object"})
seedINTNULLRandom seed for deterministic sampling
stopTEXTNULLUp to 4 sequences where the API will stop generating
temperatureFLOATNULLSampling temperature (0 to 2). Higher = more random
top_pFLOATNULLNucleus sampling parameter (0 to 1)
toolsJSONBNULLList of tools the model may call
tool_choiceJSONBNULLControls which tool is called
openai_userTEXTNULLUnique identifier for the end-user
extra_headersJSONBNULLAdditional HTTP headers
extra_queryJSONBNULLAdditional query parameters
verboseBOOLEANFALSEEnable verbose logging
client_configJSONBNULLAdvanced client configuration

Returns

JSONB: The complete HTTP response including headers and body.