OpenAI extension (preview)
The amphi_openai extension calls the OpenAI Responses API through an explicit
SQL function. It is a Rust package integrated with the server. The call is
volatile, may incur external charges, and is not undone by ROLLBACK.
Configure the master key as a systemd credential (amphi-secret-key in
$CREDENTIALS_DIRECTORY) before creating secrets. This is the only supported
method; the key must contain 64 hexadecimal characters (32 bytes). The API key
is encrypted in the local secret store and must not be passed to the function.
CREATE SCHEMA openai;
CREATE EXTENSION amphi_openai WITH SCHEMA openai;
CREATE SECRET openai_api_key
TYPE TEXT
VALUE '...';
CREATE EXTERNAL CONNECTION openai_prod
PROVIDER openai
OPTIONS (api_key = SECRET openai_api_key);
The function accepts the connection name, model, system instructions, and user
input. It returns a document with id, model, text, and usage:
SELECT openai.complete(
'openai_prod',
'gpt-...',
'Answer in one sentence.',
'What is a B-tree?'
) AS response;
SELECT openai.complete(
'openai_prod', 'gpt-...', 'Answer in one sentence.', 'What is a B-tree?'
) ->> 'text' AS answer;
Each function evaluation makes an external request. Avoid calling it from a query that evaluates many rows: each row may create a billable API call. A global concurrency limit and batch function are not available yet.
The first cut uses https://api.openai.com/v1/responses, does not retry
automatically, and limits each prompt to 64 KiB and the response to 1 MiB. Rate
limits, authentication failures, timeouts, and protocol errors return SQL errors
without including the API key or remote response body. Requests follow the
OpenAI Responses API.
CREATE SECRET writes to encrypted storage outside the SQL transaction, so it
must run in autocommit and cannot be rolled back. The statement audit event
redacts its plaintext. Logical dumps include the extension installation and an
OpenAI connection that contains only SECRET references, but never the secret
store. Provision the same secret name and type on the target before running
amprestore; the restored connection then resolves it. Until external-connection
ACLs exist, only administrators can create or invoke an OpenAI connection.
Secret rotation and deletion, fine-grained authorization, batch calls,
streaming, tools, and embeddings are outside this preview.