快速开始
获取您的 API 密钥
前往您的 Venice API 设置 并生成新的 API 密钥。如需详细的操作指南,请查看 API 密钥指南。
设置您的 API 密钥
将您的 API 密钥添加到您的环境中。您可以在 shell 中导出它:或将其添加到项目中的
export VENICE_API_KEY='your-api-key-here'
.env 文件:VENICE_API_KEY=your-api-key-here
安装 SDK
Venice 与 OpenAI 兼容,因此您可以使用 OpenAI SDK。如果您更喜欢使用 cURL 或原始 HTTP 请求,可以跳过此步骤。
pip install openai
npm install openai
发送您的第一个请求
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("VENICE_API_KEY"),
base_url="https://api.venice.ai/api/v1"
)
completion = client.chat.completions.create(
model="zai-org-glm-5",
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "Why is privacy important?"}
]
)
print(completion.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.VENICE_API_KEY,
baseURL: 'https://api.venice.ai/api/v1'
});
const completion = await client.chat.completions.create({
model: 'zai-org-glm-5',
messages: [
{ role: 'system', content: 'You are a helpful AI assistant' },
{ role: 'user', content: 'Why is privacy important?' }
]
});
console.log(completion.choices[0].message.content);
curl https://api.venice.ai/api/v1/chat/completions \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org-glm-5",
"messages": [
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "Why is privacy important?"}
]
}'
system- 模型应如何表现的指令user- 您的 prompt 或问题assistant- 之前的模型响应(用于多轮对话)tool- 函数调用结果(使用工具时)
通过更改模型 ID 切换模型
每个请求都包含一个
model ID。要使用不同的模型,请更改请求中的 model 值。热门选择:zai-org-glm-5- 大多数用例的默认模型kimi-k2-6- 适用于更复杂任务的强大推理claude-opus-4-8- 适用于复杂任务的高智能模型venice-uncensored-1-2- Venice 的无审查模型
查看所有模型
浏览包含定价、能力和上下文限制的完整模型列表
使用 Venice 参数
您可以选择使用 查看所有可用参数。
venice_parameters 启用 Venice 特有的功能,如网页搜索:import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("VENICE_API_KEY"),
base_url="https://api.venice.ai/api/v1"
)
completion = client.chat.completions.create(
model="zai-org-glm-5",
messages=[
{"role": "user", "content": "What are the latest developments in AI?"}
],
extra_body={
"venice_parameters": {
"enable_web_search": "auto",
"include_venice_system_prompt": True
}
}
)
print(completion.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.VENICE_API_KEY,
baseURL: 'https://api.venice.ai/api/v1'
});
const completion = await client.chat.completions.create({
model: 'zai-org-glm-5',
messages: [
{ role: 'user', content: 'What are the latest developments in AI?' }
],
venice_parameters: {
enable_web_search: 'auto',
include_venice_system_prompt: true
}
});
console.log(completion.choices[0].message.content);
curl https://api.venice.ai/api/v1/chat/completions \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org-glm-5",
"messages": [
{"role": "user", "content": "What are the latest developments in AI?"}
],
"venice_parameters": {
"enable_web_search": "auto",
"include_venice_system_prompt": true
}
}'
启用流式传输(可选)
使用
stream=True 实时流式传输响应:import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("VENICE_API_KEY"),
base_url="https://api.venice.ai/api/v1"
)
stream = client.chat.completions.create(
model="zai-org-glm-5",
messages=[{"role": "user", "content": "Write a short story about AI"}],
stream=True
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.VENICE_API_KEY,
baseURL: 'https://api.venice.ai/api/v1'
});
const stream = await client.chat.completions.create({
model: 'zai-org-glm-5',
messages: [{ role: 'user', content: 'Write a short story about AI' }],
stream: true
});
for await (const chunk of stream) {
if (chunk.choices && chunk.choices[0]?.delta?.content) {
process.stdout.write(chunk.choices[0].delta.content);
}
}
curl https://api.venice.ai/api/v1/chat/completions \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org-glm-5",
"messages": [
{"role": "user", "content": "Write a short story about AI"}
],
"stream": true
}'
自定义响应行为(可选)
使用 temperature、max tokens 等参数控制模型的响应方式:有关所有支持参数的更多信息,请查看 Chat Completions 文档。
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("VENICE_API_KEY"),
base_url="https://api.venice.ai/api/v1"
)
completion = client.chat.completions.create(
model="zai-org-glm-5",
messages=[
{"role": "system", "content": "You are a creative storyteller"},
{"role": "user", "content": "Tell me a creative story"}
],
temperature=0.8,
max_tokens=500,
top_p=0.9,
frequency_penalty=0.5,
presence_penalty=0.5,
extra_body={
"venice_parameters": {
"include_venice_system_prompt": False
}
}
)
print(completion.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.VENICE_API_KEY,
baseURL: 'https://api.venice.ai/api/v1'
});
const completion = await client.chat.completions.create({
model: 'zai-org-glm-5',
messages: [
{ role: 'system', content: 'You are a creative storyteller' },
{ role: 'user', content: 'Tell me a creative story' }
],
temperature: 0.8,
max_tokens: 500,
top_p: 0.9,
frequency_penalty: 0.5,
presence_penalty: 0.5,
venice_parameters: {
include_venice_system_prompt: false
}
});
console.log(completion.choices[0].message.content);
curl https://api.venice.ai/api/v1/chat/completions \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org-glm-5",
"messages": [
{"role": "system", "content": "You are a creative storyteller"},
{"role": "user", "content": "Tell me a creative story"}
],
"temperature": 0.8,
"max_tokens": 500,
"top_p": 0.9,
"frequency_penalty": 0.5,
"presence_penalty": 0.5,
"stream": false,
"venice_parameters": {
"include_venice_system_prompt": false
}
}'
更多能力
图像生成
使用扩散模型从文本 prompt 创建图像:import os
import requests
url = "https://api.venice.ai/api/v1/image/generate"
payload = {
"model": "venice-sd35",
"prompt": "A cyberpunk city with neon lights and rain",
"width": 1024,
"height": 1024,
"format": "webp"
}
headers = {
"Authorization": f"Bearer {os.getenv('VENICE_API_KEY')}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = 'https://api.venice.ai/api/v1/image/generate';
const options = {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENICE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'venice-sd35',
prompt: 'A cyberpunk city with neon lights and rain',
width: 1024,
height: 1024,
format: 'webp'
})
};
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
curl https://api.venice.ai/api/v1/image/generate \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "venice-sd35",
"prompt": "A cyberpunk city with neon lights and rain",
"width": 1024,
"height": 1024
}'
images 数组中返回 base64 编码的图像。解码 base64 字符串以保存或显示图像。
热门图像模型:
qwen-image- 最高质量的图像生成venice-sd35- 默认选择,适用于所有功能hidream- 用于生产用途的快速生成
查看所有图像模型
查看所有可用图像模型及其定价和能力
cfg_scale、negative_prompt、style_preset、seed、variants 等,请查看 图像 API 参考。
图像编辑
使用 Qwen-Image 模型通过 AI 驱动的修复修改现有图像:import os
import requests
import base64
url = "https://api.venice.ai/api/v1/image/edit"
with open("image.jpg", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode('utf-8')
payload = {
"prompt": "Colorize",
"image": image_base64
}
headers = {
"Authorization": f"Bearer {os.getenv('VENICE_API_KEY')}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
with open("edited_image.png", "wb") as f:
f.write(response.content)
import fs from 'fs';
const imageBuffer = fs.readFileSync('image.jpg');
const imageBase64 = imageBuffer.toString('base64');
const options = {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENICE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'Colorize',
image: imageBase64
})
};
const response = await fetch('https://api.venice.ai/api/v1/image/edit', options);
const imageData = await response.arrayBuffer();
fs.writeFileSync('edited_image.png', Buffer.from(imageData));
curl --request POST \
--url https://api.venice.ai/api/v1/image/edit \
--header "Authorization: Bearer $VENICE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"prompt": "Colorize",
"image": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAAIGNIUk0A..."
}'
图像放大
将图像增强并放大到更高分辨率:import os
import requests
import base64
url = "https://api.venice.ai/api/v1/image/upscale"
with open("image.jpg", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode('utf-8')
payload = {
"image": image_base64,
"scale": 2
}
headers = {
"Authorization": f"Bearer {os.getenv('VENICE_API_KEY')}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
with open("upscaled_image.png", "wb") as f:
f.write(response.content)
import fs from 'fs';
const imageBuffer = fs.readFileSync('image.jpg');
const imageBase64 = imageBuffer.toString('base64');
const options = {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENICE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
image: imageBase64,
scale: 2
})
};
const response = await fetch('https://api.venice.ai/api/v1/image/upscale', options);
const imageData = await response.arrayBuffer();
fs.writeFileSync('upscaled_image.png', Buffer.from(imageData));
curl --request POST \
--url https://api.venice.ai/api/v1/image/upscale \
--header "Authorization: Bearer $VENICE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"image": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAAIGNIUk0A...",
"scale": 2
}'
文本转语音
使用 50+ 种多语言声音将文本转换为音频:import os
import requests
response = requests.post(
"https://api.venice.ai/api/v1/audio/speech",
headers={
"Authorization": f"Bearer {os.getenv('VENICE_API_KEY')}",
"Content-Type": "application/json"
},
json={
"input": "Hello, welcome to Venice Voice.",
"model": "tts-kokoro",
"voice": "af_sky"
}
)
with open("speech.mp3", "wb") as f:
f.write(response.content)
import fs from 'fs';
const response = await fetch('https://api.venice.ai/api/v1/audio/speech', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENICE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
input: 'Hello, welcome to Venice Voice.',
model: 'tts-kokoro',
voice: 'af_sky'
})
});
const audioBuffer = await response.arrayBuffer();
fs.writeFileSync('speech.mp3', Buffer.from(audioBuffer));
curl --request POST \
--url https://api.venice.ai/api/v1/audio/speech \
--header "Authorization: Bearer $VENICE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"input": "Hello, welcome to Venice Voice.",
"model": "tts-kokoro",
"voice": "af_sky"
}' \
--output speech.mp3
tts-kokoro 模型支持 50+ 种多语言声音,包括 af_sky、af_nova、am_liam、bf_emma、zf_xiaobei 和 jm_kumo。
有关所有声音选项,请参阅 TTS API。
语音转文本
将音频文件转录为文本:import os
import requests
url = "https://api.venice.ai/api/v1/audio/transcriptions"
with open("audio.mp3", "rb") as f:
response = requests.post(
url,
headers={"Authorization": f"Bearer {os.getenv('VENICE_API_KEY')}"},
files={"file": f},
data={
"model": "nvidia/parakeet-tdt-0.6b-v3",
"response_format": "json"
}
)
print(response.json())
import fs from 'fs';
import FormData from 'form-data';
const form = new FormData();
form.append('file', fs.createReadStream('audio.mp3'));
form.append('model', 'nvidia/parakeet-tdt-0.6b-v3');
form.append('response_format', 'json');
const response = await fetch('https://api.venice.ai/api/v1/audio/transcriptions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENICE_API_KEY}`,
...form.getHeaders()
},
body: form
});
const data = await response.json();
console.log(data);
curl --request POST \
--url https://api.venice.ai/api/v1/audio/transcriptions \
--header "Authorization: Bearer $VENICE_API_KEY" \
--form file=@audio.mp3 \
--form model=nvidia/parakeet-tdt-0.6b-v3 \
--form response_format=json
timestamps=true 以获取字级时间数据。
有关所有选项,请参阅 Transcriptions API。
Embeddings
为语义搜索、RAG 和推荐生成向量嵌入:import os
import requests
url = "https://api.venice.ai/api/v1/embeddings"
payload = {
"model": "text-embedding-bge-m3",
"input": "Privacy-first AI infrastructure for semantic search",
"encoding_format": "float"
}
headers = {
"Authorization": f"Bearer {os.getenv('VENICE_API_KEY')}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = 'https://api.venice.ai/api/v1/embeddings';
const options = {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENICE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'text-embedding-bge-m3',
input: 'Privacy-first AI infrastructure for semantic search',
encoding_format: 'float'
})
};
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
curl --request POST \
--url https://api.venice.ai/api/v1/embeddings \
--header "Authorization: Bearer $VENICE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "text-embedding-bge-m3",
"input": "Privacy-first AI infrastructure for semantic search",
"encoding_format": "float"
}'
Vision(多模态)
使用支持视觉的模型如qwen3-vl-235b-a22b 与文本一起分析图像:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("VENICE_API_KEY"),
base_url="https://api.venice.ai/api/v1"
)
response = client.chat.completions.create(
model="qwen3-vl-235b-a22b",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{
"type": "image_url",
"image_url": {"url": "https://www.gstatic.com/webp/gallery/1.jpg"}
}
]
}
]
)
print(response.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.VENICE_API_KEY,
baseURL: 'https://api.venice.ai/api/v1'
});
const response = await client.chat.completions.create({
model: 'qwen3-vl-235b-a22b',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'What is in this image?' },
{
type: 'image_url',
image_url: { url: 'https://www.gstatic.com/webp/gallery/1.jpg' }
}
]
}
]
});
console.log(response.choices[0].message.content);
curl https://api.venice.ai/api/v1/chat/completions \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-vl-235b-a22b",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image_url",
"image_url": {
"url": "https://www.gstatic.com/webp/gallery/1.jpg"
}
}
]
}
]
}'
函数调用
定义模型可以调用以与外部工具和 API 交互的函数:import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("VENICE_API_KEY"),
base_url="https://api.venice.ai/api/v1"
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state"
}
},
"required": ["location"]
}
}
}
]
response = client.chat.completions.create(
model="zai-org-glm-5",
messages=[{"role": "user", "content": "What's the weather in San Francisco?"}],
tools=tools
)
print(response.choices[0].message)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.VENICE_API_KEY,
baseURL: 'https://api.venice.ai/api/v1'
});
const tools = [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the current weather in a location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state'
}
},
required: ['location']
}
}
}
];
const response = await client.chat.completions.create({
model: 'zai-org-glm-5',
messages: [{ role: 'user', content: "What's the weather in San Francisco?" }],
tools: tools
});
console.log(response.choices[0].message);
curl https://api.venice.ai/api/v1/chat/completions \
-H "Authorization: Bearer $VENICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "zai-org-glm-5",
"messages": [
{
"role": "user",
"content": "What'\''s the weather in San Francisco?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state"
}
},
"required": ["location"]
}
}
}
]
}'
下一步
既然您已经发出了第一个请求,请进一步探索 Venice API 提供的更多内容:浏览模型
比较所有可用模型及其能力、定价和上下文限制
API 参考
探索包含所有端点和参数的详细 API 文档
结构化响应
了解如何获取具有保证 schema 的 JSON 响应
AI Agents 指南
使用 agent 应用、编码 agent、MCP 工具、skill 和加密货币工作流进行构建
其他资源
速率限制
了解速率限制和生产使用的最佳实践
错误代码
处理 API 错误和故障排查的参考
Postman Collection
导入我们的完整 Postman collection 以方便测试
隐私与安全
了解 Venice 的隐私优先架构和数据处理
需要帮助?
- Discord 社区:加入我们的 Discord 服务器 获取支持和讨论
- 文档:浏览我们的 完整 API 参考
- 状态页:在 veniceai-status.com 检查服务状态
- Twitter:关注 @AskVenice 获取更新