图像生成
Portkey 的 AI 网关支持许多基础模型提供商提供的图像生成能力。最常见的用例是 文本到图像,用户发送一个提示,图像模型处理该提示并返回一张图像。
文本到图像的使用
Portkey 支持 OpenAI 签名以进行文本到图像请求。
import Portkey from 'portkey-ai';
// Initialize the Portkey client
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
virtualKey: "VIRTUAL_KEY" // Add your provider's virtual key
});
async function main() {
const image = await portkey.images.generate({
model: "dall-e-3",
prompt: "Lucy in the sky with diamonds"
});
console.log(image.data);
}
main();from portkey_ai import Portkey
from IPython.display import display, Image
# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VIRTUAL_KEY" # Add your provider's virtual key
)
image = portkey.images.generate(
model="dall-e-3",
prompt="Lucy in the sky with diamonds"
)
# Display the image
display(Image(url=image.data[0].url))API 参考
创建图像完成后,请求将记录在日志 UI 中,可以查看图像。
(请注意,提供者可能会在一段时间后删除托管的图像,因此某些日志可能仅包含 URL)

支持的提供商和模型
以下提供商支持图像生成,更多提供商将很快加入。请提交请求或PR以将模型或提供商添加到AI网关。
提供商
模型
功能
Replicate (即将推出)
Monster API (即将推出)
Segmind (即将推出)
Together AI (即将推出)
食谱
这是一个关于使用 Portkey 进行图像生成的详细食谱,展示了如何使用多个提供者及通过配置在它们之间进行路由。
Last updated