> ## Documentation Index
> Fetch the complete documentation index at: https://docs.venice.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 快速开始

> Venice API 快速入门 — 生成 API 密钥，发送你的第一个聊天补全请求，并在几分钟内探索图像、视频和音频端点。

只需几分钟即可开始使用 Venice API。生成 API 密钥，发出你的第一个请求，然后开始构建。

## 快速开始

<Steps>
  <Step title="获取你的 API 密钥">
    前往 [Venice API 设置](https://venice.ai/settings/api) 并生成一个新的 API 密钥。

    如需详细步骤，请查阅 [API 密钥指南](/guides/getting-started/generating-api-key)。
  </Step>

  <Step title="配置你的 API 密钥">
    将你的 API 密钥添加到环境变量中。你可以在 shell 中导出它：

    ```bash theme={"system"}
    export VENICE_API_KEY='your-api-key-here'
    ```

    或者添加到项目中的 `.env` 文件：

    ```bash theme={"system"}
    VENICE_API_KEY=your-api-key-here
    ```
  </Step>

  <Step title="安装 SDK">
    Venice 兼容 OpenAI，因此你可以直接使用 OpenAI SDK。如果你更倾向于使用 cURL 或原始 HTTP 请求，可以跳过此步骤。

    <CodeGroup>
      ```bash Python theme={"system"}
      pip install openai
      ```

      ```bash Node.js theme={"system"}
      npm install openai
      ```
    </CodeGroup>
  </Step>

  <Step title="发送你的第一个请求">
    <CodeGroup>
      ```python Python theme={"system"}
      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)
      ```

      ```javascript Node.js theme={"system"}
      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);
      ```

      ```bash cURL theme={"system"}
      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?"}
          ]
        }'
      ```
    </CodeGroup>

    **消息角色：**

    * `system` - 关于模型应如何行为的指令
    * `user` - 你的提示或问题
    * `assistant` - 模型的历史回复（用于多轮对话）
    * `tool` - 函数调用结果（使用工具时）
  </Step>

  <Step title="通过更改模型 ID 切换模型">
    每个请求都包含一个 `model` ID。要使用不同的模型，请更改请求中的 `model` 值。常用选项：

    * `zai-org-glm-5` - 适用于大多数场景的默认模型
    * `kimi-k2-6` - 面向更复杂任务的强推理能力
    * `claude-opus-4-8` - 适用于复杂任务的高智能模型
    * `venice-uncensored-1-2` - Venice 的无审查模型

    <Card title="查看所有模型" icon="database" href="/overview/models">
      浏览完整的模型列表，包含定价、能力和上下文限制
    </Card>
  </Step>

  <Step title="使用 Venice 参数">
    你可以通过 `venice_parameters` 启用 Venice 特有的功能，例如网络搜索：

    <CodeGroup>
      ```python Python theme={"system"}
      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)
      ```

      ```javascript Node.js theme={"system"}
      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);
      ```

      ```bash cURL theme={"system"}
      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
          }
        }'
      ```
    </CodeGroup>

    查看所有[可用参数](https://docs.venice.ai/api-reference/api-spec#venice-parameters)。
  </Step>

  <Step title="启用流式传输（可选）">
    使用 `stream=True` 实时流式接收响应：

    <CodeGroup>
      ```python Python theme={"system"}
      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="")
      ```

      ```javascript Node.js theme={"system"}
      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);
          }
      }
      ```

      ```bash cURL theme={"system"}
      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
        }'
      ```
    </CodeGroup>
  </Step>

  <Step title="自定义响应行为（可选）">
    使用 temperature、max tokens 等参数来控制模型的响应方式：

    <CodeGroup>
      ```python Python theme={"system"}
      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)
      ```

      ```javascript Node.js theme={"system"}
      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);
      ```

      ```bash cURL theme={"system"}
      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
          }
        }'
      ```
    </CodeGroup>

    查看 [Chat Completions 文档](/api-reference/endpoint/chat/completions) 了解所有受支持参数的更多信息。
  </Step>
</Steps>

***

## 后续步骤

现在你已经完成了第一次请求，可以继续探索 Venice API 提供的更多功能：

<CardGroup cols={2}>
  <Card title="浏览模型" icon="database" href="/overview/models">
    对比所有可用模型的能力、定价和上下文限制
  </Card>

  <Card title="API 参考" icon="code" href="/api-reference/api-spec">
    浏览详尽的 API 文档，包含所有端点和参数
  </Card>

  <Card title="结构化响应" icon="brackets-curly" href="/guides/features/structured-responses">
    学习如何获取带有保证模式的 JSON 响应
  </Card>

  <Card title="AI 智能体指南" icon="robot" href="/guides/integrations/ai-agents">
    使用智能体应用、代码智能体、MCP 工具、技能以及加密工作流进行构建
  </Card>
</CardGroup>

### 更多资源

<CardGroup cols={2}>
  <Card title="速率限制" icon="gauge" href="/api-reference/rate-limiting">
    了解速率限制以及生产环境使用的最佳实践
  </Card>

  <Card title="错误代码" icon="triangle-exclamation" href="/api-reference/error-codes">
    处理 API 错误和排查问题的参考
  </Card>

  <Card title="Postman 集合" icon="bolt" href="/guides/getting-started/postman">
    导入我们完整的 Postman 集合以便轻松测试
  </Card>

  <Card title="隐私与安全" icon="shield" href="/overview/privacy">
    了解 Venice 的隐私优先架构和数据处理方式
  </Card>
</CardGroup>

***

## 需要帮助？

* **Discord 社区**：加入我们的 [Discord 服务器](https://discord.gg/askvenice) 获取支持并参与讨论
* **文档**：浏览我们的 [完整 API 参考](/api-reference/api-spec)
* **状态页面**：在 [veniceai-status.com](https://veniceai-status.com) 查看服务状态
* **Twitter**：关注 [@AskVenice](https://x.com/AskVenice) 获取最新动态

<Resources />
