全部產品
Search
文件中心

API Gateway:管理Model API

更新時間:Jan 08, 2026

Model API適用於面向人工智慧應用開發的團隊,提供了更加靈活和智能的AI網關配置和調試能力。它可以用於各種AI代理、AI觀測、消費者鑒權、Alibaba Content Security Service防護等外掛程式的預置。本文主要介紹了如何建立、編輯、調試和刪除Model API。

建立Model API

  1. 開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID

  2. 在左側導覽列,單擊Model API,然後單擊建立Model API

  3. 選擇使用情境,並單擊對應情境的建立按鈕。

    不同的情境會影響後續協議可選項與系統自動建立的預設路由,當前支援:

    • 文本產生(Text):支援 OpenAI 相容協議和 Anthropic 協議

    • 圖片產生(Image)

    • 視頻產生(Video)

    • 語音合成(Audio)

    • 向量化(Embedding)

    • 文本排序(Rerank)

    • 其他(Others)

  4. 配置基本資料。

    在彈窗中先完成選擇使用情境,進入建立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-maxqwen-long

      • 多模型服務(按權重):選擇多個 AI 服務並設定權重,支援透傳或改寫模型名。

      • 多服務(按觀測指標):系統將根據各服務的回應時間、成功率等觀測指標自動選擇最優服務進行請求路由,無需手動設定權重。

      • 多模型服務(智能路由):系統將根據模型特徵為請求自動選擇最合適的模型,詳情參考智能路由

        說明

        多服務(按觀測指標)和多模型服務(智能路由)需要將AI網關版本升級至2.1.15及以上。

    • Fallback: 可開啟並按順序配置多條 Fallback 策略(可複用同一服務)。

    • 首包逾時:用於控制流程式響應中從請求發送到接收到第一個響應包之間的最大等待時間,適用於對響應延遲敏感的流式互動情境。(單位為毫秒,設為0時表示不啟用)。

    • 資源群組:支援選擇預設或已有資源群組,也可建立。資源群組用於對賬戶資源分組管理、授權與監控。

      如需建立新的資源群組,您可以單擊建立資源群組完成建立。
  5. 確認配置參數並單擊確定完成建立。

預設路由

在不同使用情境下選擇不同協議時,系統將自動建立預設路由

文本產生(Text)

協議:OpenAI 相容(OpenAI/v1

路由名稱

路徑

方法

說明

create-chat-completion

/v1/chat/completions

POST

Creates a model response for the given chat conversation。

create-completion

/v1/completions

POST

Creates a completion for the provided prompt and parameters。

協議:Anthropic(Anthropic

Anthropic協議專為Claude等Anthropic系列模型設計,提供原生的訊息格式和互動方式。該協議適用於需要使用Anthropic原生API格式的應用情境。

說明

支援該協議的大模型供應商包括:阿里雲百鍊(Qwen)、Claude、月之暗面(Moonshot)、智譜 AI(ZhipuAI)等。以上供應商AI服務自動支援Anthropic協議,無需額外配置。

路由名稱

路徑

方法

說明

create-message

/v1/messages

POST

Creates a message for the given chat conversation using Anthropic's native message format。

圖片產生(Image)

協議:阿里雲百鍊圖片產生

路由名稱

路徑

方法

說明

dashscope-text-to-image-synthesis

/api/v1/services/aigc/text2image/image-synthesis

POST

Generate a text-to-image synthesis image。

dashscope-image-to-image-synthesis

/api/v1/services/aigc/image2image/image-synthesis

POST

Generate an image-to-image synthesis image。

dashscope-image-to-image-outpainting

/api/v1/services/aigc/image2image/out-painting

POST

Generate an image-to-image outpainting image。

dashscope-virtual-model-generation

/api/v1/services/aigc/virtualmodel/generation

POST

Generate a virtual model image。

dashscope-background-generation

/api/v1/services/aigc/background-generation/generation

POST

Generate a background generation image。

tasks

/api/v1/tasks

GET/POST/PUT/PATCH/DELETE

Manage asynchronous tasks。

協議:OpenAI 相容

路由名稱

路徑

方法

說明

openai-image-generation

/api/v1/images/generations

POST

Generate an image。

openai-image-edit

/api/v1/images/edits

POST

Edit an image。

openai-image-variation

/api/v1/images/variations

POST

Variation an image。

協議:ComfyUI

路由名稱

路徑

方法

說明

comfyui-websocket

/ws

GET

WebSocket endpoint for real-time communication with the server.

comfyui-embeddings

/embeddings

GET

Retrieve a list of the names of embeddings available.

comfyui-extensions

/extensions

GET

Retrieve a list of the extensions registering a WEB_DIRECTORY.

comfyui-features

/features

GET

Retrieve server features and capabilities.

comfyui-models

/models

GET

Retrieve a list of available model types.

comfyui-models-folder

/models/{folder}

GET

Retrieve models in a specific folder.

comfyui-workflow-templates

/workflow_templates

GET

Retrieve a map of custom node modules and associated template workflows.

comfyui-upload-image

/upload/image

POST

Upload an image.

comfyui-upload-mask

/upload/mask

POST

Upload a mask.

comfyui-view

/view

GET

View an image. Lots of options.

comfyui-view-metadata

/view_metadata/

GET

Retrieve metadata for a model.

comfyui-system-stats

/system_stats

GET

Retrieve information about the system (python version, devices, vram etc).

comfyui-prompt

/prompt

GET/POST

Retrieve current queue status and execution information or submit a prompt to the queue.

comfyui-object-info

/object_info

GET

Retrieve details of all node types.

comfyui-object-info-class

/object_info/{node_class}

GET

Retrieve details of one node type.

comfyui-history

/history

GET/POST

Retrieve the queue history.

comfyui-history-prompt-id

/history/{prompt_id}

GET

Retrieve the queue history for a specific prompt.

comfyui-queue

/queue

GET/POST

Retrieve the current state of the execution queue or manage queue operations.

comfyui-interrupt

/interrupt

POST

Stop the current workflow execution.

comfyui-free

/free

POST

Free memory by unloading specified models.

comfyui-userdata

/userdata

GET

List user data files in a specified directory.

comfyui-userdata-v2

/v2/userdata

GET

Enhanced version that lists files and directories in structured format.

comfyui-userdata-file

/userdata/{file}

GET/POST/DELETE

Retrieve, upload, update or delete a specific user data file.

comfyui-userdata-file-move

/userdata/{file}/move/{dest}

POST

Move or rename a user data file.

comfyui-users

/users

GET/POST

Get user information or create a new user.

視頻產生(Video)

協議:阿里雲百鍊視頻產生

路由名稱

路徑

方法

說明

dashscope-video-generation-synthesis

/api/v1/services/aigc/video-generation/video-synthesis

POST

Generate a video-generation synthesis video。

dashscope-image-to-video-synthesis

/api/v1/services/aigc/image2video/video-synthesis

POST

Generate an image-to-video synthesis video。

tasks

/api/v1/tasks

GET/POST/PUT/PATCH/DELETE

Manage asynchronous tasks。

語音合成(Audio)

協議:阿里雲百鍊語音合成

路由名稱

路徑

方法

說明

dashscope-text-to-audio-synthesis

/api-ws/v1/inference

GET

Generate a text-to-audio synthesis audio。

協議:OpenAI 相容(OpenAI/v1

路由名稱

路徑

方法

說明

openai-audio-speech

/api/v1/audio/speech

POST

Generate speech audio。

向量化(Embedding)

協議:OpenAI 相容(OpenAI/v1

路由名稱

路徑

方法

說明

create-embedding

/v1/embeddings

POST

Creates an embedding vector representing the input text。

文本排序(Rerank)

協議:阿里雲百鍊文本排序

路由名稱

路徑

方法

說明

rerank

/api/v1/services/rerank/text-rerank/text-rerank

POST

Rerank the given documents to be sorted based on query relevance。

協議:vLLM(vLLM

路由名稱

路徑

方法

說明

rerank

/v1/rerank

POST

Rerank the given documents to be sorted based on query relevance。

其他(Others)

協議:OpenAI 相容(OpenAI/v1

路由名稱

路徑

方法

說明

models

/v1/models

GET/POST/PUT/PATCH/DELETE

Manage models。

files

/v1/files

GET/POST/PUT/PATCH/DELETE

Manage files。

batches

/v1/batches

GET/POST/PUT/PATCH/DELETE

Manage batches。

fine-tuning

/v1/fine_tuning

GET/POST/PUT/PATCH/DELETE

Manage fine-tuning jobs。

說明

相容性說明:對於支援Anthropic協議的大模型供應商(阿里雲百鍊、Claude、月之暗面、智譜 AI等),建立AI服務時會自動支援多種協議,包括OpenAI相容協議和Anthropic協議,使用者可根據需要選擇合適的協議建立Model API。

智能路由

在企業級智能應用情境中,隨著大語言模型能力的多樣化發展,不同模型在特定領域展現出差異化的優勢:

  • 代碼產生:Qwen-Coder系列在代碼理解和產生方面表現優異。

  • 數學推理:Qwen-Math系列擅長複雜數學問題的求解。

  • 翻譯任務:Qwen-MT系列針對多語言翻譯進行了專項最佳化。

  • 快速響應:Qwen-Flash系列在延遲敏感情境下提供極速響應。

  • 複雜推理:Qwen-Max、DeepSeek-R1等模型在複雜邏輯推理上更勝一籌。

然而,在實際應用中面臨以下挑戰:

  1. 使用者體驗割裂:使用者需要手動選擇模型,難以判斷哪個模型最適合當前任務。

  2. 資源利用不均:簡單任務使用高成本模型造成資源浪費。

  3. 開發複雜度高:應用程式層需要實現複雜的路由邏輯,增加開發和維護成本。

  4. 缺乏統一入口:多模型部署導致 API 分散,難以統一管理。

為應對以上問題,AI網關設計實現模型語義智能路由功能,通過語義分析自動將使用者請求路由到最合適的模型服務,支援以下意圖分類

IntentCode

描述

典型情境

Coder

代碼編寫與調試

編程問題、代碼產生、Bug修複

Math

數學計算與推理

數學證明、公式推導、統計分析

Translation

多語言翻譯

文檔翻譯、即時翻譯、本地化

Flash

快速簡單響應

簡單問答、資訊查詢、日常對話

Complex

複雜邏輯推理

深度分析、複雜決策、長文本理解

編輯Model API

  1. 開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID

  2. 在左側導覽列,單擊Model API,單擊目標API操作列的編輯。在編輯Model API面板中修改相關參數配置。關於配置參數說明,請參見建立Model API

  3. 確認配置資訊並單擊確定

調試Model API

說明

當前只支援文本產生的/v1/chat/completions調試。

  1. 開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID

  2. 在左側導覽列,選擇Model API,單擊目標API操作列的調試

  3. 調試面板中,選擇網域名稱和模型,按需開啟流式請求開關、配置參數設定和自訂參數。在右側模型返回頁簽中,輸入調試內容並單擊發送進行調試。

    image

刪除Model API

  1. 開啟AI網關控制台執行個體頁面,在頂部功能表列選擇目標執行個體所在地區,並單擊目標執行個體ID

  2. 在左側導覽列,選擇Model API,單擊目標API操作列下的刪除,在確認刪除的彈框中輸入API名稱,然後單擊刪除