管理Model API

Model API适用于面向人工智能应用开发的团队,提供了更加灵活和智能的AI网关配置和调试能力。它可以用于各种AI代理、AI观测、消费者鉴权、内容安全防护等插件的预置。本文主要介绍了如何创建、编辑、调试和删除Model API。

创建Model API

  1. 打开AI网关控制台实例页面,在顶部菜单栏选择目标实例所在地域,并单击目标实例ID

  2. 在左侧导航栏,单击Model API,然后单击创建Model API

  3. 选择使用场景,并单击对应场景的创建按钮。

    不同的场景会影响后续协议可选项与系统自动创建的默认路由,当前支持:

    • 文本生成(Text)

    • 图片生成(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 日志投递服务。

      重要

      启用后系统会记录所有 AI 请求内容(包括请求体 body)到访问日志,请妥善配置 SLS 并做好数据安全防护。

    • 大模型服务: 支持单模型服务多模型服务(按模型名称)多模型服务(按权重)

      • 单模型服务:选择 1 个 AI 服务,并可设置模型名称(可透传或改写)。

      • 多模型服务(按模型名称):根据请求体中的模型名按规则匹配到不同服务;匹配规则支持通配符 ?*,例如 qwen-* 可匹配 qwen-maxqwen-long

      • 多模型服务(按权重):选择多个 AI 服务并设置权重,支持透传或改写模型名。

    • Fallback: 可开启并按顺序配置多条 Fallback 策略(可复用同一服务)。

    • 资源组:支持选择默认或已有资源组,也可新建。资源组用于对账户资源分组管理、授权与监控。

      如需创建新的资源组,您可以单击创建资源组完成创建。
  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。

图片生成(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。

说明

兼容性说明:旧版本创建的LLM API,系统会创建 3 条默认路由:create-chat-completioncreate-completioncreate-embedding,在当前版本会被识别为文本生成类型。

编辑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名称,然后单击删除