Use data definition language (DDL) statements in Flink SQL to register, view, modify, and delete AI models.
Usage notes
-
Supported model services: Alibaba Cloud Model Studio, Platform for AI (PAI), and other services with OpenAI-compatible interfaces.
-
PAI model services must be in the same region as your Realtime Compute for Apache Flink service.
-
Requires Ververica Runtime (VVR) 11.1 or later.
CREATE MODEL
Register an AI model so Flink SQL jobs can call it.
Create a script and enter the following statement in the SQL editor:
CREATE [TEMPORARY] MODEL [catalog_name.][db_name.]model_name
INPUT ( { <physical_column_definition> [, ...n] )
OUTPUT ( { <physical_column_definition> [, ...n] )
WITH (key1=val1, key2=val2, ...)
<physical_column_definition>:
column_name column_type [COMMENT column_comment]
Clauses
| Clause | Description | Schema requirements | Example |
|---|---|---|---|
INPUT |
Defines the names, types, and order of input columns. | Exactly one STRING column is required. |
INPUT ( ` input_text STRING COMMENT 'User comment')` |
OUTPUT |
Defines the names, types, and order of output columns. | chat/completions: exactly one STRING column. embeddings: exactly one ARRAY<FLOAT> column. |
OUTPUT ( ` sentiment_label STRING COMMENT 'Sentiment label')` |
WITH |
Specifies connection and model parameters. See Parameters. | None. | WITH ('provider'='bailian', 'endpoint'='${ENDPOINT}', 'model'='qwen-turbo', 'apiKey'='${KEY}') |
Examples
Register a chat model (Alibaba Cloud Model Studio)
CREATE MODEL model_bailian
INPUT (`input` STRING)
OUTPUT (`content` STRING)
WITH (
'provider'='bailian',
'endpoint'='<Endpoint>',
'api-key'='<bailian-key>',
'model'='qwen3-235b-a22b'
);
The endpoint format is <base-url>/compatible-mode/v1/<task>, for example https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions.
base-url:
-
Internet access:
https://dashscope-intl.aliyuncs.com. To use internet access, enable public access for your Flink workspace. For details, see Network connectivity selection. -
Internal network access: See Access Alibaba Cloud Model Studio through endpoints over internal networkSingapore. Currently only the Singapore region is supported.
task: The model task type. Valid values: chat/completions, embeddings.
Register an embedding model (PAI)
CREATE MODEL model_pai
INPUT (`input` STRING)
OUTPUT (`embedding` ARRAY<FLOAT>)
WITH (
'provider'='bailian',
'endpoint'='<vpc_endpoint>',
'api-key'='<Token>',
'model'='qwen3-235b-a22b'
);
To get the VPC endpoint and API key from the PAI console:
-
Log on to the PAI console.
-
In the left navigation pane, choose Model Gallery > Job Management > Deployment Jobs, then click the target task name.
-
Click View Invocation Information.
The VPC invocation address uses HTTP — change it to HTTPS and append /v1/<task> to the URL. For example: https://************.vpc.cn-hangzhou.pai-eas.aliyuncs.com/api/predict/quickstart_deploy_20250722_7b22/v1/chat/completions. The Token value is used as the api-key parameter.
For details, see One-click deployment of DeepSeek-V3 and DeepSeek-R1 models.
Parameters
General
| Parameter | Required | Description |
|---|---|---|
provider |
Yes | The model service provider. Always set to bailian. |
endpoint |
Yes | The API endpoint of Alibaba Cloud Model Studio or an OpenAI-compatible service. For Alibaba Cloud Model Studio and PAI endpoints, see Examples. For other services, refer to the service's API documentation. |
api-key |
Yes | The API key for the model service. See Obtain API key. In VVR 11.1, use apiKey. |
max-context-size |
No | The maximum context length per request. When the limit is exceeded, the behavior is controlled by context-overflow-action. Requires VVR 11.2 or later. |
context-overflow-action |
No | How to handle requests that exceed max-context-size. Default: truncated-tail. Requires VVR 11.2 or later. See valid values below. |
Valid values for `context-overflow-action`:
| Value | Behavior |
|---|---|
truncated-tail |
Truncates the context from the end to fit max-context-size, without logging. |
truncated-tail-log |
Truncates the context from the end to fit max-context-size and logs the truncation. |
truncated-head |
Truncates the context from the beginning to fit max-context-size, without logging. |
truncated-head-log |
Truncates the context from the beginning to fit max-context-size and logs the truncation. |
skipped |
Drops the record without logging. |
skipped-log |
Drops the record and logs it. |
chat/completions
| Parameter | Required | Description |
|---|---|---|
model |
Yes | The text generation model to call. See supported models. Billed based on the model and the number of input and output tokens. |
system-prompt |
Yes | The system prompt sent with each request. Default: You are a helpful assistant. In VVR 11.1, use systemPrompt. |
temperature |
No | Controls output randomness. Valid range: [0, 2); 0 is not recommended. Higher values produce more varied output; lower values make output more deterministic. |
top-p |
No | Controls output diversity by limiting token selection to a cumulative probability threshold. Higher values introduce more randomness. In VVR 11.1, use topP. |
stop |
No | A string that stops generation when it appears in the output. |
max-tokens |
No | The maximum number of tokens in the generated output. In VVR 11.1, use maxTokens. |
embeddings
| Parameter | Required | Description |
|---|---|---|
model |
Yes | The text embedding model to call. See supported models. Billed based on the model and the number of input and output tokens. |
dimension |
No | The output vector dimension. Default: 1024. Valid values: 1024, 768, 512. Other values cause an error. |
View models
Create a script and run one of the following statements in the SQL editor.
List registered models:
SHOW MODELS [ ( FROM | IN ) [catalog_name.]database_name ];
Show the DDL statement used to register a model:
SHOW CREATE MODEL [catalog_name.][db_name.]model_name;
Show the input and output schema of a model:
DESCRIBE MODEL [catalog_name.][db_name.]model_name;
Example
SHOW MODELS;
-- Result
--+------------+
--| model name |
--+------------+
--| m |
--+------------+
DESCRIBE MODEL m;
-- Result
-- +---------+--------+------+----------+
-- | name | type | null | is input |
-- +---------+--------+------+----------+
-- | content | STRING | TRUE | TRUE |
-- | label | BIGINT | TRUE | FALSE |
-- +---------+--------+------+----------+
Modify models
Create a script and enter one of the following statements in the SQL editor.
ALTER MODEL [IF EXISTS] [catalog_name.][db_name.]model_name {
RENAME TO new_table_name
SET (key1=val1, ...)
RESET (key1, ...)
}
Examples
Rename a model:
ALTER MODEL m RENAME TO m1;
Update a parameter:
ALTER MODEL m SET ('endpoint' = '<Your_Endpoint>');
Reset a parameter to its default value:
ALTER MODEL m RESET ('endpoint');
Delete models
Create a script and enter the following statement in the SQL editor.
DROP [TEMPORARY] MODEL [IF EXISTS] [catalog_name.][db_name.]model_name
Example
DROP MODEL m;