How to Connect OpenRouter API to Airtable

October 3, 2025
5 min read
OpenRouter

If you're looking to connect OpenRouter's API to Airtable, you've come to the right place. I recently built a solution for this, and I'm going to show you how to get started with the basics.

Why Connect OpenRouter to Airtable?

OpenRouter gives you access to dozens of AI models (OpenAI, Claude, Gemini, DeepSeek, and more) through a single API. When you combine that with Airtable's database capabilities, you can automate AI-powered tasks like content generation, data enrichment, and text analysis—all directly in your spreadsheets.

What You'll Need

Before we start, make sure you have:

The Basic Connection

Here's the core of how I connect OpenRouter to Airtable. The key is using Airtable's remoteFetchAsync() function to make API calls:

async function callOpenRouter(prompt, apiKey, model) {
    const endpoint = 'https://openrouter.ai/api/v1/chat/completions';
    
    const payload = {
        model: model,
        messages: [
            { role: 'user', content: prompt }
        ],
        max_tokens: 500,
        temperature: 0.7
    };
    
    const response = await remoteFetchAsync(endpoint, {
        method: 'POST',
        headers: {
            'Authorization': 'Bearer ' + apiKey,
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(payload)
    });
    
    const json = await response.json();
    return json.choices[0].message.content;
}

This function takes your prompt, sends it to OpenRouter, and returns the AI's response. Simple as that.

A Quick Example

Let's say you have an Airtable with a "Prompt" column and you want to fill an "Output" column with AI responses. Here's how you'd use it:

let table = base.getTable("Your Table Name");
let records = await table.selectRecordsAsync();

for (let record of records.records) {
    let prompt = record.getCellValue("Prompt");
    
    if (prompt) {
        let response = await callOpenRouter(
            prompt,
            "your-api-key-here",
            "openai/gpt-4o"
        );
        
        await table.updateRecordsAsync([{
            id: record.id,
            fields: { "Output": response }
        }]);
    }
}

You'd run this as an Airtable script, and it would process each row one by one.

Error Handling (Important!)

In production, you'll want error handling. API calls can fail, rate limits happen, and models sometimes return empty responses. Here's a basic wrapper:

try {
    const response = await remoteFetchAsync(endpoint, options);
    
    if (response.status !== 200) {
        console.error("API Error:", response.status);
        return "Error: API call failed";
    }
    
    const json = await response.json();
    return json.choices[0].message.content || "Empty response";
    
} catch (error) {
    console.error("Request failed:", error);
    return "Error: " + error.message;
}

Going Beyond the Basics

Now, the script I showed you above works great for simple use cases. But when I was building this for my own projects, I needed more:

  • Processing multiple prompt/output field pairs simultaneously
  • Configurable temperature and token limits
  • System prompts for consistent tone
  • Web search integration (yes, OpenRouter supports this!)
  • Citation removal for cleaner outputs
  • Smart error handling (continue vs. stop on errors)

So I built a production-ready script that handles all of this through a clean configuration interface. If you're interested in a plug-and-play solution that just works, check it out here. It's saved me hours of manual work.

🎉 Learn more about the script here

Note: I've also built a similar solution for Google Sheets that includes image generation capabilities. If you're working with Google Sheets instead, check out that version here.

Tips I've Learned

1. Start with a View: Instead of processing your entire table, create an Airtable view that filters to just the records you want to process. Much safer for testing.

2. Check for Existing Outputs: Always check if an output field already has content before making an API call. This prevents duplicate charges:

let existingOutput = record.getCellValue("Output");
if (existingOutput) continue; // Skip if already processed

3. Monitor Your Costs: OpenRouter shows you real-time costs at openrouter.ai/activity. Keep an eye on it, especially with premium models like GPT-4.

4. Temperature Matters: For factual tasks, use 0.1-0.3. For creative writing, go 0.7-0.9. This makes a bigger difference than you'd think.

Final Thoughts

Connecting OpenRouter to Airtable opens up a ton of possibilities. Whether you're generating product descriptions, analyzing customer feedback, or creating content at scale, this combination is powerful.

The basic script I shared will get you started, but if you need something more robust without the development headache, feel free to grab my production script. It's what I use daily, and it handles all the edge cases I ran into building this.

🎉 Get the production-ready Airtable script here