Model API適用於面向人工智慧應用開發的團隊,提供了更加靈活和智能的AI網關配置和調試能力。它可以用於各種AI代理、AI觀測、消費者鑒權、Alibaba Content Security Service防護等外掛程式的預置。本文主要介紹了如何建立、編輯、調試和刪除Model API。
建立Model API
開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID。
在左側導覽列,單擊Model API,然後單擊建立Model API。
選擇使用情境,並單擊對應情境的建立按鈕。
不同的情境會影響後續協議可選項與系統自動建立的預設路由,當前支援:
文本產生(Text):支援 OpenAI 相容協議和 Anthropic 協議
圖片產生(Image)
視頻產生(Video)
語音合成(Audio)
向量化(Embedding)
文本排序(Rerank)
其他(Others)
配置基本資料。
在彈窗中先完成選擇使用情境,進入建立Model API表單後,您可按以下說明進行配置:
協議:不同協議對應該情境下的一組內建預設路由,用於快速產生常用的 OpenAI/DashScope/vLLM 等相容介面。
API名稱:您可自訂API名稱,需注意名稱必須全域唯一(同一帳號下不可重複),支援英文、數字、底線“_”、“-”,且不超過64個字元。
網域名稱:訪問該 API 的網域名稱,支援選擇多個。網域名稱與基本路徑
BasePath的組合必須唯一。如果還沒有網域名稱,請單擊右側添加網域名稱按鈕完成建立。
Base Path:配置API的基本請求路徑,預設為
/。可選擇是否啟用轉寄至後端服務時移除。說明開啟轉寄至後端服務時移除後,當請求轉寄到後端服務時,系統會自動移除請求路徑中的BasePath部分。例如:
BasePath設定為 /api
原始請求路徑 /api/users
實際轉寄到後端的路徑變為 /users
AI 請求觀測: 開啟後可查看 Metrics、Logging、Tracing 資訊。Logging 與 Tracing 依賴 SLS 日誌投遞服務。可勾選開啟記錄請求內容與記錄響應內容,開啟後將記錄對大模型的請求或大模型返回的Context。
重要啟用後系統會記錄所有 AI 請求內容(包括請求體 body)到訪問日誌,請妥善配置 SLS 並做好資料安全防護。
大模型服務: 支援單模型服務、多模型服務(按模型名稱)、多模型服務(按權重)。
單模型服務:選擇 1 個 AI 服務,並可設定模型名稱(可透傳或改寫)。
多模型服務(按模型名稱):根據請求體中的模型名按規則匹配到不同服務;匹配規則支援萬用字元
?與*,例如qwen-*可匹配qwen-max、qwen-long。多模型服務(按權重):選擇多個 AI 服務並設定權重,支援透傳或改寫模型名。
Fallback: 可開啟並按順序配置多條 Fallback 策略(可複用同一服務)。
首包逾時:用於控制流程式響應中從請求發送到接收到第一個響應包之間的最大等待時間,適用於對響應延遲敏感的流式互動情境。(單位為毫秒,設為0時表示不啟用)。
資源群組:支援選擇預設或已有資源群組,也可建立。資源群組用於對賬戶資源分組管理、授權與監控。
如需建立新的資源群組,您可以單擊建立資源群組完成建立。
確認配置參數並單擊確定完成建立。
預設路由說明
下面為您介紹在不同使用情境下選擇不同協議時,系統自動建立的預設路由。
文本產生(Text)
協議:OpenAI 相容(OpenAI/v1)
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Creates a model response for the given chat conversation。 |
|
| POST | Creates a completion for the provided prompt and parameters。 |
協議:Anthropic(Anthropic)
Anthropic協議專為Claude等Anthropic系列模型設計,提供原生的訊息格式和互動方式。該協議適用於需要使用Anthropic原生API格式的應用情境。
支援該協議的大模型供應商包括:阿里雲百鍊(Qwen)、Claude、月之暗面(Moonshot)、智譜 AI(ZhipuAI)等。以上供應商AI服務自動支援Anthropic協議,無需額外配置。
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Creates a message for the given chat conversation using Anthropic's native message format。 |
圖片產生(Image)
協議:阿里雲百鍊圖片產生
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Generate a text-to-image synthesis image。 |
|
| POST | Generate an image-to-image synthesis image。 |
|
| POST | Generate an image-to-image outpainting image。 |
|
| POST | Generate a virtual model image。 |
|
| POST | Generate a background generation image。 |
|
| GET/POST/PUT/PATCH/DELETE | Manage asynchronous tasks。 |
協議:OpenAI 相容
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Generate an image。 |
|
| POST | Edit an image。 |
|
| POST | Variation an image。 |
協議:ComfyUI
路由名稱 | 路徑 | 方法 | 說明 |
|
| GET | WebSocket endpoint for real-time communication with the server. |
|
| GET | Retrieve a list of the names of embeddings available. |
|
| GET | Retrieve a list of the extensions registering a WEB_DIRECTORY. |
|
| GET | Retrieve server features and capabilities. |
|
| GET | Retrieve a list of available model types. |
|
| GET | Retrieve models in a specific folder. |
|
| GET | Retrieve a map of custom node modules and associated template workflows. |
|
| POST | Upload an image. |
|
| POST | Upload a mask. |
|
| GET | View an image. Lots of options. |
|
| GET | Retrieve metadata for a model. |
|
| GET | Retrieve information about the system (python version, devices, vram etc). |
|
| GET/POST | Retrieve current queue status and execution information or submit a prompt to the queue. |
|
| GET | Retrieve details of all node types. |
|
| GET | Retrieve details of one node type. |
|
| GET/POST | Retrieve the queue history. |
|
| GET | Retrieve the queue history for a specific prompt. |
|
| GET/POST | Retrieve the current state of the execution queue or manage queue operations. |
|
| POST | Stop the current workflow execution. |
|
| POST | Free memory by unloading specified models. |
|
| GET | List user data files in a specified directory. |
|
| GET | Enhanced version that lists files and directories in structured format. |
|
| GET/POST/DELETE | Retrieve, upload, update or delete a specific user data file. |
|
| POST | Move or rename a user data file. |
|
| GET/POST | Get user information or create a new user. |
視頻產生(Video)
協議:阿里雲百鍊視頻產生
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Generate a video-generation synthesis video。 |
|
| POST | Generate an image-to-video synthesis video。 |
|
| GET/POST/PUT/PATCH/DELETE | Manage asynchronous tasks。 |
語音合成(Audio)
協議:阿里雲百鍊語音合成
路由名稱 | 路徑 | 方法 | 說明 |
|
| GET | Generate a text-to-audio synthesis audio。 |
協議:OpenAI 相容(OpenAI/v1)
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Generate speech audio。 |
向量化(Embedding)
協議:OpenAI 相容(OpenAI/v1)
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Creates an embedding vector representing the input text。 |
文本排序(Rerank)
協議:阿里雲百鍊文本排序
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Rerank the given documents to be sorted based on query relevance。 |
協議:vLLM(vLLM)
路由名稱 | 路徑 | 方法 | 說明 |
|
| POST | Rerank the given documents to be sorted based on query relevance。 |
其他(Others)
協議:OpenAI 相容(OpenAI/v1)
路由名稱 | 路徑 | 方法 | 說明 |
|
| GET/POST/PUT/PATCH/DELETE | Manage models。 |
|
| GET/POST/PUT/PATCH/DELETE | Manage files。 |
|
| GET/POST/PUT/PATCH/DELETE | Manage batches。 |
|
| GET/POST/PUT/PATCH/DELETE | Manage fine-tuning jobs。 |
相容性說明:對於支援Anthropic協議的大模型供應商(阿里雲百鍊、Claude、月之暗面、智譜 AI等),建立AI服務時會自動支援多種協議,包括OpenAI相容協議和Anthropic協議,使用者可根據需要選擇合適的協議建立Model API。
編輯Model API
開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID。
在左側導覽列,單擊Model API,單擊目標API操作列的編輯。在編輯Model API面板中修改相關參數配置。關於配置參數說明,請參見建立Model API。
確認配置資訊並單擊確定。
調試Model API
當前只支援文本產生的/v1/chat/completions調試。
開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID。
在左側導覽列,選擇Model API,單擊目標API操作列的調試。
在調試面板中,選擇網域名稱和模型,按需開啟流式請求開關、配置參數設定和自訂參數。在右側模型返回頁簽中,輸入調試內容並單擊發送進行調試。

刪除Model API
開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID。
在左側導覽列,選擇Model API,單擊目標API操作列下的刪除,在確認刪除的彈框中輸入API名稱,然後單擊刪除。