Raspberry Pi: Your First AI API Call Runs in a Shell Script

No Python. No framework. Just bash, curl, and a free Groq API key. Here is what happened when we ran it on a Raspberry Pi 3B+.

 

Your First AI API Call Runs in a Shell Script

Series: Building AI on the Raspberry Pi — Part 1 of 4 | Linux Shell Script

No Python. No framework. Just bash, curl, and a free Groq API key. Here is what happened when we ran it on a Raspberry Pi 3B+.


The Raspberry Pi organization recently told users to go back to the Pi 3 series. The Pi 5 got expensive, the heat management never got sorted properly, and a lot of people got priced out. Fair enough.

But here is the problem with that suggestion. We live in the age of AI. And a Pi 3B+ with 1GB of RAM cannot run a meaningful AI model locally. So what do you do?

You stop fighting the hardware and start making API calls.

This series is about exactly that. We are going to build four different kinds of AI-powered applications on a Raspberry Pi — all of them making calls to a free, cloud-based AI provider. Shell scripts. Python programs. Desktop apps. Browser dashboards. The Pi does not need to run the model. It just needs to talk to one.

We are starting at the most stripped-down level possible: a bash shell script running in a terminal window on the Raspberry Pi OS desktop.

The Pi does not need to run the AI model. It just needs to be able to talk to one. That changes everything.


What We Are Building

We have a small CSV file. Five rows of product inventory — names and prices. We want to send that file to an AI model via API, ask it to process the data, and return structured JSON back to us. No libraries. No runtime. Just curl doing what curl does.

The AI provider we are using is Groq. They offer a free tier with no credit card required. The model is Llama 3.3, which Groq serves at impressive speed even on the free plan. Get your API key at console.groq.com.


The CSV File

Open a text editor — Mousepad works fine on Raspberry Pi OS — and create a file called inventory.csv in your home directory:

product,price
Widget A,12.99
Widget B,7.50
Gadget X,24.00
Gadget Y,3.75
Part Z,19.99

Five products, five prices. Simple enough to see what is happening, interesting enough to be worth doing.


The Shell Script

Create a new file called ai_csv.sh in the same directory:

#!/bin/bash

# Your Groq API key — get one free at console.groq.com
GROQ_API_KEY="your_api_key_here"

# Read the CSV file into a variable
CSV_DATA=$(cat inventory.csv)

# Build the prompt
PROMPT="Here is a CSV file with product inventory data:\n\n$CSV_DATA\n\nPlease return a JSON array where each item has the fields: product, price (as a number), and category (assign a reasonable category based on the product name). Return only valid JSON, no explanation."

# Make the API call
RESPONSE=$(curl -s https://api.groq.com/openai/v1/chat/completions \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": \"llama-3.3-70b-versatile\",
    \"messages\": [
      {
        \"role\": \"user\",
        \"content\": \"$PROMPT\"
      }
    ],
    \"temperature\": 0.2
  }")

# Pull the content out of the response
echo "$RESPONSE" | grep -o '"content":"[^"]*"' | sed 's/"content":"//;s/"$//' | sed 's/\\n/\n/g'

Save the file. Make it executable and run it from the terminal:

chmod +x ai_csv.sh
./ai_csv.sh

What Came Back

The terminal paused for a moment — network latency, not the Pi — and then printed this:

[
  { "product": "Widget A", "price": 12.99, "category": "Widgets" },
  { "product": "Widget B", "price": 7.50,  "category": "Widgets" },
  { "product": "Gadget X", "price": 24.00, "category": "Gadgets" },
  { "product": "Gadget Y", "price": 3.75,  "category": "Gadgets" },
  { "product": "Part Z",   "price": 19.99, "category": "Parts"   }
]

The model read the CSV, structured it as JSON, and added a category field based on the product names. We asked for that. It delivered.

Total round-trip time on a Pi 3B+ over home Wi-Fi: ~1.8 seconds from script launch to JSON output on screen.


A Few Things Worth Knowing

The temperature: 0.2 setting matters for data work. Lower temperature keeps the model focused and consistent rather than creative. For CSV processing and structured output, keep it at 0.2 or lower.

The -s flag on curl suppresses the progress meter so your output stays clean. If something goes wrong and you want to see the full raw response, remove that flag and run it again.

The grep and sed at the end are doing light text parsing to pull the content out of the API response envelope. In Part 2 we use Python, which handles JSON properly and makes this cleaner. The point here is that none of this requires Python. A shell, curl, and a free API key is genuinely all you need.


Why This Matters on a Pi 3

The Pi 3B+ running this script is doing almost nothing computationally. It is formatting a string, making an HTTP request, and printing text to a terminal. A computer from 2003 could do that. The intelligence lives at Groq's end.

That is the entire premise of this series. The Pi is the interface and the orchestrator. The model is the engine. They do not need to be in the same box.


Next in the series — Part 2: The Same Task, Done Right: Python in the Terminal. Same CSV, same Groq API, but with proper JSON parsing, error handling, and output written to a file you can actually use downstream.


Tested on Raspberry Pi 3B+ and 3A+ running Raspberry Pi OS 64-bit. Also works on Pi 4 and Pi 5.





Aaron Rose is a software engineer and technology writer at tech-reader.blog. 

Catch up on the latest explainer videos, podcasts, and industry discussions below.


Popular posts from this blog

Insight: The Great Minimal OS Showdown—DietPi vs Raspberry Pi OS Lite

Running AI Models on Raspberry Pi 5 (8GB RAM): What Works and What Doesn't