For self-hosted PostgreSQL instances, you can provide API keys by setting an environment variable available to the PostgreSQL process. After setting the variable, reference its name in pgai functions using the api_key_name parameter.
Systemd
Add the variable to the [Service] stanza of your unit file:
Environment=MY_API_KEY=<api key here>
Docker
Use the -e flag during docker run:
docker run -e MY_API_KEY=<api key here> ... timescale/timescaledb-ha:pg17
Docker Compose
Add the variable to the environment section of your database service:
services:
db:
image: timescale/timescaledb-ha:pg17
environment:
MY_API_KEY: <api key here>
SELECT * FROM ai.openai_list_models(api_key_name => 'MY_API_KEY');