Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
This documentation page is also available as an interactive notebook. You can launch the notebook in Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the above links.
Pixeltable’s OpenAI integration enables you to access OpenAI models via the OpenAI API.

Prerequisites

Important notes

  • OpenAI usage may incur costs based on your OpenAI plan.
  • Be mindful of sensitive data and consider security measures when integrating with external services.
First you’ll need to install required libraries and enter your OpenAI API key.

Azure OpenAI

The same functions call Azure OpenAI. OPENAI_API_KEY is the Azure key, and OPENAI_BASE_URL is the resource endpoint, passed through as the client’s base_url. OPENAI_API_VERSION is sent as the api-version query parameter; for the /openai/v1/ endpoint use preview or latest. The model argument is the deployment name on that resource.
chat_completions(..., model='your-deployment') then uses that client. The examples below are the same call, with an OpenAI model name or an Azure deployment name. Now let’s create a Pixeltable directory to hold the tables for our demo.
Created directory ‘openai_demo’.
<pixeltable.catalog.dir.Dir at 0x3108bfe90>

Chat completions

Create a Table: In Pixeltable, create a table with columns to represent your input data and the columns where you want to store the results from OpenAI.
Created table ‘chat’.
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Inserted 1 row with 0 errors in 1.68 s (0.60 rows/s)

Responses API

The Responses API is OpenAI’s recommended API for new projects. It offers built-in tools (web search, file search, code interpreter), improved reasoning model performance, lower costs, and cleaner semantics compared to Chat Completions. Key benefits:
  • instructions parameter: Cleanly separates system-level guidance from user input
  • Built-in tools: Use web_search, file_search, code_interpreter natively
  • Multi-turn via previous_response_id: Simpler conversation state management
Created table ‘responses’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Inserted 1 row with 0 errors in 1.93 s (0.52 rows/s)

Decisions

The Decisions API answers predicate, choice, and score questions about a text or image input. Each answer is a probability, a choice, or a score instead of generated text. decisions() requires openai>=3.32. This example checks food-delivery complaints against the customer’s photo. A reply_prompt() UDF returns None unless the photo supports the complaint, and a None input skips the responses() call, so only supported complaints get a drafted reply.
Created table ‘complaints’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.00 s
Added 0 column values with 0 errors in 0.00 s
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 2 rows with 0 errors in 2.04 s (0.98 rows/s)
2 rows inserted.

Embeddings

Note: OpenAI Embeddings API is not available with free tier API keys
Created table ‘embeddings’.
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Inserted 1 row with 0 errors in 0.58 s (1.72 rows/s)
1 row inserted.

Image generations

Created table ‘images’.
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Inserted 1 row with 0 errors in 19.41 s (0.05 rows/s)
1 row inserted.

Audio Transcription

Created table ‘audio’.
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Inserted 1 row with 0 errors in 5.34 s (0.19 rows/s)
1 row inserted.
‘Allow me to illustrate. During the last 60 days, I have been at the task of constructing an administration. It has been a long and deliberate process. Some have counseled greater speed. Others have counseled more expedient tests. But I have been guided by the standard John Winthrop set before his shipmates on the flagship Arabella 331 years ago, as they too faced the task of building a new government on a perilous frontier. We must always consider, he said, that we shall be as a city upon a hill. The eyes of all peoples are upon us. Today the eyes of all people are truly upon us. And our governments, in every branch, at every level,‘

Learn more

To learn more about advanced techniques like RAG operations in Pixeltable, check out the RAG Operations in Pixeltable tutorial.
Last modified on October 30, 2026