Add an AI Model and chat with your data (Optional)
Optional. Add an OpenAI, Anthropic, or xAI model and chat with the NYC Taxi Trips dataset.
Complete Add a Dataset and query data first so the model has a dataset to answer questions about.
Adding a Model Provider
- Navigate to Build > Code.
- In Components sidebar, click Model Providers tab, and select the provider that matches your key: OpenAI, Anthropic, or xAI.
- Enter the Model name.
- Enter the Model ID for the provider (e.g.
gpt-4o,claude-sonnet-4-6, orgrok-4.6). - Set the provider API Key secret.
- API keys and other secrets are securely stored and encrypted. See Secrets.
- Insert
tools: autoin theparamssection of the Model to automatically connect datasets to the model.
The final Spicepod configuration in the editor should match the tab for your provider:
name: my-first-app
kind: Spicepod
version: v1beta1
datasets:
- from: s3://spiceai-demo-datasets/taxi_trips/2024/
name: samples.taxi_trips
description: Taxi trips dataset from Spice.ai demo datasets.
params:
file_format: parquet
models:
- from: openai:gpt-4o
name: gpt-4o
params:
endpoint: https://api.openai.com/v1
openai_api_key: ${secrets:OPENAI_API_KEY}
tools: autoname: my-first-app
kind: Spicepod
version: v1beta1
datasets:
- from: s3://spiceai-demo-datasets/taxi_trips/2024/
name: samples.taxi_trips
description: Taxi trips dataset from Spice.ai demo datasets.
params:
file_format: parquet
models:
- from: anthropic:claude-sonnet-4-6
name: claude-sonnet-4-6
params:
anthropic_api_key: ${secrets:ANTHROPIC_API_KEY}
tools: autoname: my-first-app
kind: Spicepod
version: v1beta1
datasets:
- from: s3://spiceai-demo-datasets/taxi_trips/2024/
name: samples.taxi_trips
description: Taxi trips dataset from Spice.ai demo datasets.
params:
file_format: parquet
models:
- from: xai:grok-4.6
name: grok-4-6
params:
xai_api_key: ${secrets:XAI_API_KEY}
tools: autoSee OpenAI, Anthropic, and xAI for the full list of parameters for each provider.
- Click Save in the code toolbar and then Deploy in the popup card that appears in the bottom right to deploy the changes.
- Navigate to Playground and select AI Chat in the sidebar.
- Ask a question about the NYC Taxi Trips dataset in the chat. For example:
- "What datasets are available?"
- "What is the average fare amount of a taxi trip?"
[Optional] Call chat completions API using cURL
- Replace
[API-KEY]in the sample below with the project API Key, and[MODEL-NAME]with the modelnamefrom the Spicepod (e.g.gpt-4o), then execute in a terminal.
curl --request POST \
--url 'https://data.spiceai.io/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: [API-KEY]' \
--data '{ "messages": [{ "role": "user", "content": "Hello!" }], "model": "[MODEL-NAME]" }'🎉 Congratulations, you've now added an AI model and can use it to ask questions of the NYC Taxi Trips dataset.
Continue to Next Steps.