How to Connect ChatGPT to Airtable
Connecting ChatGPT to Airtable gives you the superpower to get answers to 100s of questions in no time. Here's how to do that:
You need the following things to be able to connect ChatGPT to Airtable:
- A paid Airtable account (the lowest plan is $24/month)
- OpenAI API key (you'll have to set up a payment method on OpenAI, here)
- The Scripting extension from Airtable (no additional cost), and
- A script to call the OpenAI API inside Airtable
And below is the function that you can use to call the OpenAI from inside the Airtable and get the output.
async function getGPTResponse() {
const userInput = "why is the sky blue?";
const maxTokens = 500;
const temperature = 0.7;
const model = "gpt-4.1";
const systemPrompt = "be precise";
const messages = [
{ role: "system", content: systemPrompt },
{ role: "user", content: userInput },
];
const res = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${openaiApiKey}`,
},
body: JSON.stringify({
model,
messages,
max_tokens: maxTokens,
temperature,
}),
});
const data = await res.json();
return data.choices?.[0]?.message?.content || null;
}
Here, userInput
is the prompt that you give AI, maxTokens
is the max tokens for the model, temperature
is model temperature, and systemPrompt
is the system prompt. The prompt here is hardcoded, but you can modify the script to dynamically fetch prompts from each row and then get the outputs accordingly.
ChatGPT is very good at doing this implementation as per your base data, you can just give the above script and other details in the prompt, and it will give you the final code that you can put inside the Scripting extension.
Also, there's a generic version of this script at InvertedStone that you can also get and use. You can generate almost any kind of content using this script, not just from ChatGPT but also from other AI models like Claude, Gemini, Perplexity, and more.
- ← Previous
Donald Knuth about understanding - Next →
List of cool MCP servers
Comment via email