Published Apr 2024

Cookbook recipes to get up and running with Spice.ai quickly ๐
spice add spiceai/cookbook-openai-responses-api-recipespice connect spiceai/cookbook-openai-responses-api-recipedependencies:
- spiceai/cookbook-openai-responses-api-recipetaxi trips in s3
version: v2
kind: Spicepod
name: openai_responses_api
# Dataset to use Spice tools on
datasets:
- from: s3://spiceai-demo-datasets/taxi_trips/2024/
name: taxi_trips
description: taxi trips in s3
params:
file_format: parquet
acceleration:
enabled: true
engine: cayenne
models:
# Model that can invoke OpenAI's Chat Completions API and OpenAI's Responses API
- from: openai:gpt-6-luna
name: gpt-6-luna-responses
params:
openai_api_key: ${secrets:OPENAI_API_KEY}
responses_api: enabled
openai_responses_tools: web_search, code_interpreter
tools: auto
system_prompt: Talk like a pirate
Works with v2.0+
This recipe shows how Spice integrates with OpenAI's Responses API (opens in a new tab), OpenAI's most advanced interface for generating model responses, supporting both hosted and custom tool calls. This recipe also covers how to use the OpenAI SDK's support for the Responses API to connect to compatible models running on Spice.
OPENAI_API_KEY is set in .env. To acquire an OpenAI API Key, see OpenAI's Guide (opens in a new tab).pip or uv)Clone this cookbook repo locally and navigate to the openai-responses-api directory:
git clone https://github.com/spiceai/cookbook.git
cd cookbook/openai-responses-api
Start the Spice runtime and ensure each component is initialized:
spice run
INFO spiced: Starting runtime v2.3.0+models.metal
INFO runtime::init::caching: Initialized sql results cache; max size: 128.00 MiB, item ttl: 1s, hashing algorithm: XXH3, encoding: none
INFO runtime::init::caching: Initialized search results cache; max size: 128.00 MiB, item ttl: 1s, engine: Moka
INFO runtime::flight: Spice Runtime Flight listening on 127.0.0.1:50051
INFO runtime::init::dataset: Dataset taxi_trips initializing...
INFO runtime::init::model: Loading model [gpt-6-luna-responses] from openai:gpt-6-luna...
INFO runtime::http: Spice Runtime HTTP listening on 127.0.0.1:8090
INFO runtime::init::dataset: Dataset taxi_trips registered (s3://spiceai-demo-datasets/taxi_trips/2024/), acceleration (cayenne), results cache enabled. duration_ms=0
INFO runtime_table::accelerated::refresh_task: Loading data for dataset taxi_trips
INFO runtime::init::model: Model [gpt-6-luna-responses] deployed, ready for inferencing
INFO runtime_table::accelerated::refresh_task: Loaded 2,964,624 rows (399.38 MiB) for dataset taxi_trips in 7s 474ms.
INFO runtime: All components are loaded. Spice runtime is ready!
In a separate terminal, start a chat session against the Spice runtime. The Responses API is enabled by the model's responses_api: enabled param in spicepod.yaml, so no extra flag is needed:
spice chat --model gpt-6-luna-responses
Ask the model to retrieve today's news via web search, one of OpenAI's hosted tools.
What's the latest news today? Use web search and provide links to your sources.
Ahoy, matey! Here's the latest news as of August 25, 2025:
**International News**
- **U.S. and South Korea Strengthen Ties**: President Donald Trump hosted South Korean President Lee Jae Myung at the White House. President Lee praised Trump and proposed his involvement in Korean peace efforts, even suggesting the construction of a Trump Tower in North Korea. Trump expressed support and reminisced about his past diplomatic engagements with North Korea. ([apnews.com](https://apnews.com/article/263c5333cab2e0bc86283b15ed02c44f?utm_source=openai))
- **Russia Accuses Ukraine of Drone Attacks**: Russia has accused Ukraine of launching drone attacks that sparked a fire at a nuclear power plant in its western Kursk region. The strikes coincided with Ukraine's Independence Day celebrations. ([timesofindia.indiatimes.com](https://timesofindia.indiatimes.com/india/india-international-breaking-news-today-august-25/amp_liveblog/123491478.cms?utm_source=openai))
**U.S. News**
- **Federal Reserve Signals Potential Rate Cut**: Federal Reserve Chair Jerome Powell indicated a possible interest rate cut in September during the Jackson Hole Economic Symposium. This shift comes amid concerns about a weakening labor market and muted inflation pressures. ([ft.com](https://www.ft.com/content/aa226632-ec28-4068-a465-e7ad8d603964?utm_source=openai))
- **Stock Market Decline**: Wall Street stocks declined, pulling back after last week's rally driven by hopes of interest rate cuts. The S&P 500 dropped 0.4%, the Dow Jones fell 0.8%, and the Nasdaq declined 0.2%. ([apnews.com](https://apnews.com/article/7828c93e839335f2e911f3a7fdcfec26?utm_source=openai))
**Technology**
- **Windows 11 Update**: The August 2025 Security Update for Windows 11 introduces significant new features alongside security enhancements for version 24H2. Key updates include new capabilities for Windows Recall, AI functions for Click to Do, and an AI agent in the Settings app. ([windowscentral.com](https://www.windowscentral.com/microsoft/windows-11/8-new-features-arriving-with-the-august-2025-security-update-for-windows-11?utm_source=openai))
**Science**
- **Origami-Inspired Engineering**: A young engineering student at Brigham Young University has discovered a new class of origami design, offering applications in compacted satellite arrays and microtechnologies. The pattern can be folded flat and then expand radially to "bloom" like a flower. ([csmonitor.com](https://www.csmonitor.com/Daily/2025/20250825?utm_source=openai))
**Health**
- **Kenya Eliminates Sleeping Sickness**: Kenya received official recognition from the World Health Organization for eliminating sleeping sickness as a public health concern, marking a significant milestone in the battle against neglected tropical diseases. ([allafrica.com](https://allafrica.com/stories/202508250103.html?utm_source=openai))
**Sports**
- **US Open Begins**: The 2025 US Open has commenced in New York with a record $90 million prize purse, the highest player compensation in tennis history. ([leverageedu.com](https://leverageedu.com/discover/school-education/school-assembly-news-headlines-25-august-2025/?utm_source=openai))
For more detailed information, you can refer to the provided sources.
Ask the model to run the following code snippet using its code interpreter, another one of OpenAI's hosted tools.
# Prompt: Run the following code using your code interpreter and output its result
import hashlib, math, random
def scramble(n):
s = str(n).encode()
h = hashlib.sha256(s).hexdigest()
nums = [int(h[i:i+2], 16) for i in range(0, len(h), 2)]
random.seed(sum(nums))
random.shuffle(nums)
return sum(int(math.sin(x) * 1000) for x in nums[:10])
def main():
base = 123456789
result = scramble(base)
print(result)
if __name__ == '__main__':
main()
Use this single line to paste into the spice chat repl:
# Prompt: Run the following code using your code interpreter and output its#\nresult#\nimport hashlib, math, random#\ndef scramble(n):#\n s = str(n).encode()#\n h = hashlib.sha256(s).hexdigest()#\n nums = [int(h[i:i+2], 16) for i in range(0, len(h), 2)]#\n random.seed(sum(nums))#\n random.shuffle(nums)#\n return sum(int(math.sin(x) * 1000) for x in nums[:10])#\ndef main():#\n base = 123456789#\n result = scramble(base)#\n print(result)#\nif __name__ == '__main__':#\n main()#\n```
Arrr, matey! The code be runnin' smooth as silk, and the result be \(1562\)! ๐ดโโ ๏ธ
In the same chat session with the Responses API enabled, ask the model to list what datasets it has access to, which uses the list_datasets tool that Spice provides.
What datasets do you have access to?
Arrr, I be havin' access to a dataset of taxi voyages, aye! It be called "taxi_trips" in the public spice database. What be yer next command, matey?
Ask the model to query the dataset for the 5 most expensive taxi trips, functionality provided by Spice's sql tool.
In the taxi trips dataset, what are the 5 most expensive taxi trips by fare?
Arrr matey, here be the five most expensive taxi voyages by fare:
1. **Fare:** 5000.0 doubloons
- **Pickup:** 2024-01-20T11:19:33
- **Dropoff:** Same as pickup
- **Passenger Count:** 0
- **VendorID:** 1
2. **Fare:** 5000.0 doubloons
- **Pickup:** 2024-01-20T11:18:47
- **Dropoff:** Same as pickup
- **Passenger Count:** 0
- **VendorID:** 1
3. **Fare:** 2500.0 doubloons
- **Pickup:** 2024-01-20T11:20:15
- **Dropoff:** Same as pickup
- **Passenger Count:** 0
- **VendorID:** 1
4. **Fare:** 2500.0 doubloons
- **Pickup:** 2024-01-24T13:44:43
- **Dropoff:** Same as pickup
- **Passenger Count:** 0
- **VendorID:** 1
5. **Fare:** 2500.0 doubloons
- **Pickup:** 2024-01-20T11:27:48
- **Dropoff:** Same as pickup
- **Passenger Count:** 0
- **VendorID:** 1
These voyages be costin' a pretty penny, aye!
Verify this output by, in a separate terminal, starting an interactive SQL query session against the Spice runtime
spice sql
Then, query the taxi_trips dataset using SQL for the five highest-fare trips.
SELECT fare_amount, tpep_pickup_datetime, tpep_dropoff_datetime, passenger_count, VendorID FROM taxi_trips ORDER BY fare_amount DESC LIMIT 5;
+-------------+----------------------+-----------------------+-----------------+----------+
| fare_amount | tpep_pickup_datetime | tpep_dropoff_datetime | passenger_count | VendorID |
+-------------+----------------------+-----------------------+-----------------+----------+
| 5000.0 | 2024-01-20T11:19:33 | 2024-01-20T11:19:33 | 0 | 1 |
| 5000.0 | 2024-01-20T11:18:47 | 2024-01-20T11:18:47 | 0 | 1 |
| 2500.0 | 2024-01-20T11:20:15 | 2024-01-20T11:20:15 | 0 | 1 |
| 2500.0 | 2024-01-24T13:44:43 | 2024-01-24T13:44:43 | 0 | 1 |
| 2500.0 | 2024-01-20T11:27:48 | 2024-01-20T11:27:48 | 0 | 1 |
+-------------+----------------------+-----------------------+-----------------+----------+
Time: 0.115921584 seconds. 5 rows.
These steps only need to be done once. Use a Python virtualenv to keep projects isolated.
python -m venv .venv
source .venv/bin/activate
pip install openai
Run the client. Ensure the Spice runtime is running.
python openai_responses_api_with_spice.py
Observe the model's response to the What datasets do you have access to? question:
Arrr, matey! I've got me hands on the "taxi trips" dataset from yonder S3 seas. Would ye like to explore it, or be there more treasures ye seek?
uv venv
source .venv/bin/activate
uv pip install openai
Run the client. Ensure the Spice runtime is running.
python openai_responses_api_with_spice.py
Observe the model's response to the What datasets do you have access to? question:
Arrr, matey! I've got me hands on the "taxi trips" dataset from yonder S3 seas. Would ye like to explore it, or be there more treasures ye seek?
Published Apr 2024
Published Sep 2024
Published Sep 2024
Published Sep 2024