vultr-inference
Generate images and text using Vultr's Inference API.
Setup
Uses the same API key as Vultr Cloud API. Store it at:
CODEBLOCK0
Image Generation
Available Models
| Model | Description |
|---|
| INLINECODE0 | FLUX.1-dev - High quality |
| INLINECODE1 |
FLUX.1-schnell - Fast generation |
|
stable-diffusion-3.5-medium | SD 3.5 Medium - Balanced |
Generate Image
CODEBLOCK1
Parameters
| Parameter | Type | Description |
|---|
| INLINECODE3 | string | INLINECODE4 , flux.1-schnell, INLINECODE6 |
| INLINECODE7 |
string | Text description of image |
|
n | int | Number of images (1-4) |
|
size | string |
256x256,
512x512,
1024x1024 |
|
response_format | string |
url (default) or
b64_json |
Response
CODEBLOCK2
Text Generation (Chat Completions)
Available Models
- -
llama-3.1-405b-instruct - Meta Llama 3.1 405B - INLINECODE17 - Meta Llama 3.1 70B
- INLINECODE18 - Meta Llama 3.1 8B
- INLINECODE19 - Mixtral 8x7B
- INLINECODE20 - Qwen 2 72B
Chat Completion
CODEBLOCK3
Parameters
| Parameter | Type | Description |
|---|
| INLINECODE21 | string | Model ID from list above |
| INLINECODE22 |
array | Chat messages with role and content |
|
max_tokens | int | Maximum tokens to generate |
|
temperature | float | Randomness (0-2, default 1) |
|
stream | bool | Stream response (default false) |
Python Example
CODEBLOCK4
List Available Models
CODEBLOCK5
Troubleshooting
401 Unauthorized
- - Check API key is valid
- Ensure key has inference permissions
400 Bad Request
- - Check model name is correct
- Check size is valid (256x256, 512x512, 1024x1024)
- Check prompt is not empty
Rate Limits
- - Default: 60 requests per minute
- Contact support for higher limits
vultr-inference
使用 Vultr 推理 API 生成图像和文本。
设置
使用与 Vultr 云 API 相同的 API 密钥。将其存储在:
~/.config/vultr/api_key
图像生成
可用模型
| 模型 | 描述 |
|---|
| flux.1-dev | FLUX.1-dev - 高质量 |
| flux.1-schnell |
FLUX.1-schnell - 快速生成 |
| stable-diffusion-3.5-medium | SD 3.5 Medium - 均衡 |
生成图像
bash
curl -X POST https://api.vultrinference.com/v1/images/generations \
-H Authorization: Bearer $VULTRAPIKEY \
-H Content-Type: application/json \
-d {
model: flux.1-schnell,
prompt: 一只在阿姆斯特丹吃汉堡的刺猬,
n: 1,
size: 1024x1024
}
参数
| 参数 | 类型 | 描述 |
|---|
| model | 字符串 | flux.1-dev、flux.1-schnell、stable-diffusion-3.5-medium |
| prompt |
字符串 | 图像的文本描述 |
| n | 整数 | 图像数量(1-4) |
| size | 字符串 | 256x256、512x512、1024x1024 |
| response
format | 字符串 | url(默认)或 b64json |
响应
json
{
created: 1734567890,
data: [
{
url: https://ewr.vultrobjects.com/vultrinference-images/tmp_xxx.png
}
]
}
文本生成(聊天补全)
可用模型
- - llama-3.1-405b-instruct - Meta Llama 3.1 405B
- llama-3.1-70b-instruct - Meta Llama 3.1 70B
- llama-3.1-8b-instruct - Meta Llama 3.1 8B
- mixtral-8x7b-32768 - Mixtral 8x7B
- qwen-2-72b-instruct - Qwen 2 72B
聊天补全
bash
curl -X POST https://api.vultrinference.com/v1/chat/completions \
-H Authorization: Bearer $VULTRAPIKEY \
-H Content-Type: application/json \
-d {
model: llama-3.1-70b-instruct,
messages: [
{role: user, content: 你好,你怎么样?}
],
max_tokens: 100
}
参数
| 参数 | 类型 | 描述 |
|---|
| model | 字符串 | 上方列表中的模型 ID |
| messages |
数组 | 包含角色和内容的聊天消息 |
| max_tokens | 整数 | 生成的最大令牌数 |
| temperature | 浮点数 | 随机性(0-2,默认 1) |
| stream | 布尔值 | 流式响应(默认 false) |
Python 示例
python
import os
import requests
APIKEY = open(os.path.expanduser(~/.config/vultr/apikey)).read().strip()
生成图像
response = requests.post(
https://api.vultrinference.com/v1/images/generations,
headers={Authorization: fBearer {API_KEY}},
json={
model: flux.1-schnell,
prompt: 一只吃汉堡的刺猬,
size: 512x512,
n: 1
}
)
result = response.json()
image_url = result[data][0][url]
print(f图像 URL: {image_url})
下载图像
img
response = requests.get(imageurl)
with open(generated_image.png, wb) as f:
f.write(img_response.content)
列出可用模型
bash
curl -s https://api.vultrinference.com/v1/models \
-H Authorization: Bearer $VULTRAPIKEY | jq
故障排除
401 未授权
- - 检查 API 密钥是否有效
- 确保密钥具有推理权限
400 错误请求
- - 检查模型名称是否正确
- 检查尺寸是否有效(256x256、512x512、1024x1024)
- 检查提示是否不为空
速率限制
- - 默认:每分钟 60 次请求
- 如需更高限制,请联系支持