多模型统一域名访问
介绍
为了提升用户体验和简化API调用流程,MaaS API新增了一个重要功能,支持多个模型共享同一个域名的方式调用。此功能旨在简化用户在多个模型之间的集成和管理,减少域名配置的复杂度。
在传统的调用方式中,每个模型都需要单独的域名进行访问。这虽然提供了明确的模型区分,但在多模型应用场景下,用户需要维护多个域名,增加了管理和配置的复杂度。为了解决这一问题,MaaS API现在允许用户通过一个共享的域名访问多个模型。这种方式不仅简化了域名管理,还提高了API调用的灵活性和效率。
同时,为了兼顾现有用户的使用习惯和系统稳定性,我们保留了原有的调用方式,即每个模型使用独立域名进行访问。两种方式兼容并存,用户可以根据自身需求选择最适合的调用方式。
针对新方式的最佳实践,我们提供了详细的指导,帮助用户快速上手并充分利用多域名融合的优势。
最佳实践
获取模型列表
curl --location 'https://genaiapi.cloudsway.net/v1/models' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY'
上述操作返回会列举该AK账号拥有的所有模型,针对特定模型可发起一个api请求。
{
"data": [
{
"id": "MaaS 1.5 Pro",
"created": "1720089491",
"object": "model",
"owned_by": "system"
},
{
"id": "MaaS 3 Haiku",
"created": "1720514922",
"object": "model",
"owned_by": "system"
},
{
"id": "MaaS 3 Opus",
"created": "1720514934",
"object": "model",
"owned_by": "system"
},
{
"id": "MaaS ASpeech",
"created": "1723607825",
"object": "model",
"owned_by": "system"
}
],
"object": "list"
}
文本生文本
model字段,一定要和返回的模型列表里的值保持一致
curl --location 'https://genaiapi.cloudsway.net/v1/chat/completions' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "hi"
}
]
}
],
"model":"MaaS 4o mini",
"stream": false,
"stream_options":{"include_usage":true}
}'
嵌入式
curl --location 'https://genaiapi.cloudsway.net/v1/embeddings' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
"input":"hi",
"model":"MaaS Embedding-3-large"
}'
文本生图像
MaaS Dall-e-3
curl --location 'https://genaiapi.cloudsway.net/v1/images/generations' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "一只可爱的猫咪坐在窗台上,看着外面的鸟",
"model": "MaaS Dall-E-3",
"n": 1,
"quality": "hd",
"response_format": "url",
"size": "1024x1024",
"style": "vivid",
"user": "god"
}'
MaaS-Flux-1-schnell
分endpoint方式调用
curl --request POST \
--url https://genaiapi.cloudsway.net/v2/ai/lXynAhfbOC/images/generations \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'Connection: keep-alive' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'content-type: application/json' \
--data '{
"prompts": "A beautiful and youthful high school girl is sitting in the classroom, with a bright smile on her face.",
"aspect_ratio": "2:3",
"batchsize": "2",
"step": 6
}'
根据任务id查看结果
curl --location --request GET 'https://genaiapi.cloudsway.net/v2/ai/lXynAh/images/tasks/17d1fbcf-0a05-428f-a33a-bcca22871c94' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'content-type: application/json' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--data-raw ''
统一域名方式调用
curl --location --request POST 'https://genaiapi.cloudsway.net/v2/images/generations' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'content-type: application/json' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--data-raw '{
"prompts": "A beautiful and youthful high school girl is sitting in the classroom, with a bright smile on her face.",
"aspect_ratio": "1:1",
"step": 4,
"model":"MaaS-Flux-1-schnell"
}'
根据任务id查看结果
curl --location --request GET 'https://genaiapi.cloudsway.net/v2/images/tasks/MaaS-Flux-1-schnell/17d1fbcf-0a05-428f-a33a-bcca22871c94' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'content-type: application/json' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--data-raw ''