Open AI API connectivity functions
Open AI API connectivity functions
Log in required
To access this download, you must log in.
Details
Teradata Table Operators for OpenAI-Compatible Inference Servers (v1.1.1)
This package ships two Java Table Operators (TO) that let Teradata SQL call OpenAI-compatible APIs directly from queries:
- ChatCompletion – generates text via
/v1/chat/completions - Embeddings – produces numeric embeddings via
/v1/embeddings
Both are suitable for:
- Enrichment data stored in Teradata with results of AI models running on inference servers
- Feature engineering workflows
- Operational pipelines requiring HTTP 429 rate-control resilience, custom headers, and optional TLS overrides
They are provider-agnostic (OpenAI, Azure OpenAI, NVIDIA Triton Inference Server, Ollama, etc.) so long as the service exposes OpenAI-compatible endpoints.
ChatCompletion and Embeddings: what they do, inputs, outputs
ChatCompletion
- What/why: Calls a chat model to transform or generate text (summaries, answers, classifications).
- Inputs:
- Data input: table with
txtcolumn (VARCHAR or CLOB) as the prompt. - Optional TLS input: single-row BLOB
certfor custom CA; cannot be used withIgnoreHTTPSVerification=True.
- Data input: table with
- Outputs:
response_txt(VARCHAR(OutputTextLength))- Optional diagnostics:
retries_made,last_attempt_duration,rate_limit_exceeded,rate_limit_exceeded_error_details
Embeddings
- What/why: Calls an embeddings model to convert text into a numeric vector for search, RAG, clustering, etc.
- Inputs:
- Data input: table with
txtcolumn (VARCHAR or CLOB) as the input text. - Optional TLS input: single-row BLOB
certfor custom CA; cannot be used withIgnoreHTTPSVerification=True.
- Data input: table with
- Outputs (choose format with
OutputFormat):COLUMNAR(default): one FLOAT column per dimension, named byEmbeddingPrefix(defaultemb_0,emb_1, …).BLOB: single BLOB column namedembeddingswith float32 bytes.VARBYTE: single VARBYTE column namedembeddingswith float32 bytes.- Optional diagnostics as above.
- Notes:
EmbeddingLengthis required and defines vector length.- The client enforces that the API returns at least
EmbeddingLengthvalues; otherwise it errors. EmbeddingPrefixis only valid forCOLUMNARoutput format; providing it forBLOB/VARBYTEerrors.
Parameter availability (overview)
| Parameter | ChatCompletion | Embeddings |
|---|---|---|
| BaseURL | Yes | Yes |
| ApiKey | Yes | Yes |
| IgnoreHTTPSVerification | Yes | Yes |
| HTTPProxy | Yes | Yes |
| CustomHeaders | Yes | Yes |
| BodyParameters | Yes | Yes |
| Delays | Yes | Yes |
| RetriesNumber | Yes | Yes |
| ThrowErrorOnRateLimit | Yes | Yes |
| OutputProcessingDetails | Yes | Yes |
| SystemMessage | Yes | No |
| OutputTextLength | Yes | No |
| RemoveDeepSeekThinking | Yes | No |
| EmbeddingLength | No | Yes |
| OutputFormat | No | Yes |
| EmbeddingPrefix | No | Yes (COLUMNAR only) |
Parameters (detailed)
Connection (both ChatCompletion and Embeddings)
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| BaseURL | Yes | – | Base URL of the inference server (root; not including /v1/chat/completions or /v1/embeddings). |
| ApiKey | No | – | If provided, sent as Authorization: Bearer <APIKEY>. If omitted, no Authorization header is added. |
| IgnoreHTTPSVerification | No | False | If True, disables hostname and certificate verification (dev/test only). Cannot be used together with the TLS certificate table input. |
| HTTPProxy | No | - | HTTP proxy server address in host:port format (e.g., proxy.example.com:8080). If only the host is provided, port defaults to 80. If omitted, no proxy is used |
Request (both ChatCompletion and Embeddings)
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| Model | Yes | – | Target model name. |
| BodyParameters | No | None | List of <name>:<value> pairs added directly into the JSON body. Values may be integers, floats, booleans, strings (must be wrapped in double quotes), arrays, or JSON objects.Example: BodyParameters('temperature:0.1','max_tokens:100','response_format:{"type":"json_object"}','stop:["END"]','metadata:"abc"')Notes: strings must be quoted; numbers/booleans/objects/arrays should be unquoted JSON. Unknown names pass through as-is. |
Headers (both ChatCompletion and Embeddings)
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| CustomHeaders | No | None | List of Key:Value headers to add to the HTTP request. |
Rate control (both ChatCompletion and Embeddings)
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| Delays | No | 500 | Comma-separated list of retry delays in ms for HTTP 429. If RetriesNumber exceeds the list, the last delay is reused. |
| RetriesNumber | No | 0 | Number of retries after hitting rate control (HTTP 429). |
| ThrowErrorOnRateLimit | No | False | If True and still rate-limited after retries, the function throws an error; if False, the response is NULL/empty and diagnostics indicate rate limit. |
Diagnostics (both ChatCompletion and Embeddings)
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| OutputProcessingDetails | No | False | Adds diagnostic columns: retries_made (INT), last_attempt_duration (INT, ms), rate_limit_exceeded (INT; 0/1), rate_limit_exceeded_error_details (VARCHAR(3000)). |
ChatCompletion-only
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| SystemMessage | Yes | – | System role instruction for the assistant’s behavior. |
| OutputTextLength | No | 16000 | Size of VARCHAR field for response_txt (2–32000). |
| RemoveDeepSeekThinking | No | False | If True, strips <think>...</think> blocks from responses. |
Embeddings-only
| Parameter | Mandatory? | Default | Description |
|---|---|---|---|
| EmbeddingLength | Yes | – | Positive integer specifying the vector length the function outputs. The client enforces that the API returns at least this many values. |
| OutputFormat | No | COLUMNAR | One of COLUMNAR, BLOB, VARBYTE.- COLUMNAR: one FLOAT column per dimension (EmbeddingPrefix0..N-1).- BLOB: single embeddings BLOB with float32 bytes.- VARBYTE: single embeddings VARBYTE with float32 bytes. |
| EmbeddingPrefix | No | emb_ | Column name prefix for COLUMNAR format (e.g., emb_0, emb_1, ...). If provided with BLOB or VARBYTE, an error is thrown. |
Example usage
Example Usage - Embeddings
SELECT *
FROM openai_client.Embeddings(
ON (SELECT id, txt FROM emails.emails)
ON (SELECT cert FROM sasha.pem_files WHERE id = 'cert') DIMENSION
USING
BaseURL('http://192.168.178.32:11434')
Model('qwen2.5-coder:7b')
ApiKey('FAKE-API-KEY')
Delays('200,400,800')
RetriesNumber(5)
OutputProcessingDetails('True')
ThrowErrorOnRateLimit('False')
OutputFormat('BLOB')
EmbeddingPrefix('superemb_')
BodyParameters('metadata:{"activity": "embeddings function test"}')
) AS a;Output
| id | txt | embeddings | retries_made | last_attempt_duration | rate_limit_exceeded | rate_limit_exceeded_error_details |
|---|---|---|---|---|---|---|
| 19 | I recently had a discussion... | BINARY DATA | 2 | 150 | 0 | NULL |
Example Usage - CompleteChat
SELECT *
FROM openai_client.CompleteChat(
ON (SELECT id, txt FROM emails.emails)
ON (SELECT cert FROM sasha.pem_files WHERE id = 'cert') DIMENSION
USING
BaseURL('http://192.168.178.32:11434')
SystemMessage('You are the text summarizer. Summarize in ≤10 words.')
Model('qwen2.5-coder:7b')
ApiKey('FAKE-API-KEY')
BodyParameters(
'temperature:0.1',
'max_tokens:100',
'response_format:{"type":"json_object"}',
'metadata:"summary_job"'
)
Delays('200,400,800')
RetriesNumber(5)
OutputProcessingDetails('True')
ThrowErrorOnRateLimit('False')
CustomHeaders(
'tachyon_x: XXXXXXX',
'tachyon_y: YYYYY'
)
) AS a;Output
| id | txt | response_txt | retries_made | last_attempt_duration | rate_limit_exceeded | rate_limit_exceeded_error_details |
|---|---|---|---|---|---|---|
| 19 | I recently had a discussion... | {"date":"July 7th","location":"Berlin","to... | 2 | 150 | 0 | NULL |
Installation
- Create database and grant permissions:
CREATE DATABASE openai_client AS PERM = <8000000 * number of AMPs>;
DATABASE openai_client;
GRANT CREATE EXTERNAL PROCEDURE ON openai_client TO dbc;
GRANT CREATE FUNCTION ON openai_client TO dbc;- Install the JAR:
CALL SQLJ.INSTALL_JAR(
'cj!<path to openai.client-1.1.1.jar on a client machine including file name>',
'OPENAI_CLIENT',
0
);- Create/replace the functions:
REPLACE FUNCTION openai_client.CompleteChat()
RETURNS TABLE VARYING USING FUNCTION OpenAIClientTO_contract
LANGUAGE JAVA
NO SQL
PARAMETER STYLE SQLTable
EXTERNAL NAME 'OPENAI_CLIENT:com.teradata.openai.client.ChatCompletionTO.execute()';
REPLACE FUNCTION openai_client.Embeddings()
RETURNS TABLE VARYING USING FUNCTION EmbeddingsTO_contract
LANGUAGE JAVA
NO SQL
PARAMETER STYLE SQLTable
EXTERNAL NAME 'OPENAI_CLIENT:com.teradata.openai.client.EmbeddingsTO.execute()';
- Grant execution rights:
GRANT EXECUTE FUNCTION ON openai_client TO <desired_user>;Notes
- TLS certificates: Provide via the optional
certinput table if your server requires a custom CA. Cannot be used withIgnoreHTTPSVerification=True. - Rate limiting: Retries are handled using
DelaysandRetriesNumber. Diagnostics are available withOutputProcessingDetails. - DeepSeek: Use
RemoveDeepSeekThinking('True')to strip<think>blocks. - Embeddings length:
EmbeddingLengthmust match your planned output size; the client enforces that the API returns at least that many values. - Output choice for embeddings:
COLUMNAR: best for SQL analytics, direct filtering/aggregation.BLOB/VARBYTE: compact binary storage (float32) in a single column namedembeddings; ideal for storage or external tooling.
Download Teradata Vantage Express, a free, fully-functional Teradata Vantage database, that can be up and running on your system in minutes. Please download and read the user guide for installation instructions.
Note that in order to run this VM, you'll need to install VMware Workstation Player, VMware Fusion, VMware Server, VirtualBox, or UTM on your system. For more details, see our getting started guides.
For feedback, discussion, and community support, please visit the Cloud Computing forum.
Specifications
- Version
- Released
- TTU
- OS
- Teradata