Hey guys, I'm having trouble saving the response from the OpenAI API to the database using Server Connect. The API request itself is working fine — the response comes back correctly, and I can see it in the console without any issues.
The problem is when I try to save the value (api_openai.data.choices[0].message.content
) to the database using the "Database Insert" step. Nothing gets saved.
Setup:
-
The API request is configured correctly (POST method,
Authorization
andContent-Type
headers are set)
-
The response from the API is a valid string (I confirmed this using console)
-
The database field is set as
text
API output:
{
"api_openai": {
"status": 200,
"headers": {
"date": "Wed, 12 Mar 2025 11:27:59 GMT",
"content-type": "application/json",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"access-control-expose-headers": "X-Request-ID",
"openai-organization": "improve-ai-aqyo3v",
"openai-processing-ms": "453",
"openai-version": "2020-10-01",
"x-ratelimit-limit-requests": "10000",
"x-ratelimit-limit-tokens": "200000",
"x-ratelimit-remaining-requests": "9999",
"x-ratelimit-remaining-tokens": "199973",
"x-ratelimit-reset-requests": "8.64s",
"x-ratelimit-reset-tokens": "7ms",
"x-request-id": "req_7789b318a4f780e2bbf354e31c42e",
"strict-transport-security": "max-age=31536000; includeSubDomains; preload",
"cf-cache-status": "DYNAMIC",
"set-cookie": [
"__cf_bm=NRPacFxdWIwv7x3rmhNykBcne0geAV8aMigFbSa.g-1741778879-1.0.1.1-7XIOa21cxX7NRq6o.1QlHuxKUfmhFPRJ1a82_0jucrB893x480MA5CVRcLJkO1HKF6fT_ajbJOX3aB169szwfQBcmpyY2CD4UDjCIojnmhk; path=/; expires=Wed, 12-Mar-25 11:57:59 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None",
"_cfuvid=dFAGLYmbGdjMJLSQml1ClV2a14QnLCBlLNDumEHnSEY-1741778879653-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None"
],
"x-content-type-options": "nosniff",
"server": "cloudflare",
"cf-ray": "91f2f209ab1df1b3-GRU",
"alt-svc": "h3=\":443\"; ma=86400"
},
"data": {
"id": "chatcmpl-BAEXfZkDXhXuzq3Z3E4pStbgrdhr8",
"object": "chat.completion",
"created": 1741778879,
"model": "gpt-4o-mini-2024-07-18",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! It looks like you're testing the system. How can I assist you today?",
"refusal": null,
"annotations": []
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 18,
"total_tokens": 36,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"service_tier": "default",
"system_fingerprint": "fp_06737906"
}
}
}
How can I get the value from the API response to be recognized correctly and stored in the database?
I think the issue might be that the value is not available yet when the insert is triggered — possibly because the API call is asynchronous. If that's the case, how can I create an async function in Server Connect to handle this properly?