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

# Poixe 入门指南

> 进行您的第一次 Poixe API 调用，向 ChatGPT 发送消息并获取响应。

## 前置条件

* 一个 [Poixe 账户](https://poixe.com/dashboard)
* 一个 [API 密钥](https://poixe.com/token)

## 调用 API

<Tabs>
  <Tab title="cURL">
    <Steps>
      <Step title="设置您的 API 密钥">
        从 [Poixe 控制台](https://poixe.com/dashboard) 获取您的 API 密钥并将其设置为环境变量：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        export POIXE_API_KEY='your-api-key-here'
        ```
      </Step>

      <Step title="进行您的第一次 API 调用">
        运行此命令以发送您的第一次 Poixe API 请求：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        curl https://api.poixe.com/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $POIXE_API_KEY" \
          -d '{
            "model": "gpt-5.2",
            "messages": [
              {
                "role": "user",
                "content": "Hello!"
              }
            ]
          }'
        ```

        **示例输出：**

        ```json theme={"theme":{"light":"min-light","dark":"min-dark"}}
        {
          "id": "chatcmpl-Cvjc7QFlcx3QrvEd7lysmzU849xQf",
          "object": "chat.completion",
          "created": 1767876071,
          "model": "gpt-5.2-2025-12-11",
          "choices": [
            {
              "index": 0,
              "message": {
                "role": "assistant",
                "content": "Hi—what can I help you with today?",
                "refusal": null,
                "annotations": []
              },
              "finish_reason": "stop"
            }
          ],
          "usage": {
            "prompt_tokens": 7,
            "completion_tokens": 13,
            "total_tokens": 20,
            "prompt_tokens_details": {
              "cached_tokens": 0,
              "audio_tokens": 0
            },
            "completion_tokens_details": {
              "reasoning_tokens": 0,
              "audio_tokens": 0,
              "accepted_prediction_tokens": 0,
              "rejected_prediction_tokens": 0
            }
          },
          "service_tier": "default",
          "system_fingerprint": null
        }
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="TypeScript">
    <Steps>
      <Step title="设置您的 API 密钥">
        从 [Poixe 控制台](https://poixe.com/dashboard) 获取您的 API 密钥并将其设置为环境变量：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        export POIXE_API_KEY='your-api-key-here'
        ```
      </Step>

      <Step title="安装 SDK">
        安装 OpenAI TypeScript SDK：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        npm install openai
        ```
      </Step>

      <Step title="创建您的代码">
        将其保存为 `quickstart.ts`：

        ```typescript theme={"theme":{"light":"min-light","dark":"min-dark"}}
        import OpenAI from "openai";

        const openai = new OpenAI({
          apiKey: process.env.POIXE_API_KEY!,
          baseURL: "https://api.poixe.com/v1",
        });

        async function main() {
          const completion = await openai.chat.completions.create({
            model: "gpt-5.2",
            messages: [
              { role: "system", content: "You are a helpful assistant." },
              { role: "user", content: "Hello!" },
            ],
          });

          console.log(completion.choices[0].message.content);
        }

        main();
        ```
      </Step>

      <Step title="运行您的代码">
        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        npx tsx quickstart.ts
        ```

        **示例输出：**

        ```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
        Hello! How can I help you today?
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Python">
    <Steps>
      <Step title="设置您的 API 密钥">
        从 [Poixe 控制台](https://poixe.com/dashboard) 获取您的 API 密钥并将其设置为环境变量：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        export POIXE_API_KEY='your-api-key-here'
        ```
      </Step>

      <Step title="安装 SDK">
        安装 OpenAI Python SDK：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        pip install openai
        ```
      </Step>

      <Step title="创建您的代码">
        将其保存为 `quickstart.py`：

        ```python theme={"theme":{"light":"min-light","dark":"min-dark"}}
        import os
        from openai import OpenAI

        api_key = os.environ.get("POIXE_API_KEY")
        client = OpenAI(api_key=api_key, base_url="https://api.poixe.com/v1")

        completion = client.chat.completions.create(
            model="gpt-5.2",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": "Write a short bedtime story about a unicorn."},
            ],
        )

        print(completion.choices[0].message.content)
        ```
      </Step>

      <Step title="运行您的代码">
        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        python quickstart.py
        ```

        **示例输出：**

        ```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
        Hello! How can I help today?
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Golang">
    <Steps>
      <Step title="设置您的 API 密钥">
        从 [Poixe 控制台](https://poixe.com/dashboard) 获取您的 API 密钥并将其设置为环境变量：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        export POIXE_API_KEY='your-api-key-here'
        ```
      </Step>

      <Step title="初始化 Go 模块（可选）">
        如果你是新目录，先初始化一个 Go module：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        mkdir poixe-go-quickstart && cd poixe-go-quickstart
        go mod init main
        ```
      </Step>

      <Step title="安装 SDK">
        安装 OpenAI 兼容的 Go SDK（go-openai）：

        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        go get github.com/sashabaranov/go-openai
        ```
      </Step>

      <Step title="创建您的代码">
        将其保存为 `main.go`：

        ```go theme={"theme":{"light":"min-light","dark":"min-dark"}}
        package main

        import (
        	"context"
        	"fmt"
        	"os"

        	"github.com/sashabaranov/go-openai"
        )

        func main() {
        	apiKey := os.Getenv("POIXE_API_KEY")
        	if apiKey == "" {
        		fmt.Println("POIXE_API_KEY is not set")
        		os.Exit(1)
        	}

        	cfg := openai.DefaultConfig(apiKey)
        	cfg.BaseURL = "https://api.poixe.com/v1"
        	client := openai.NewClientWithConfig(cfg)

        	resp, err := client.CreateChatCompletion(
        		context.Background(),
        		openai.ChatCompletionRequest{
        			Model: "gpt-5.2",
        			Messages: []openai.ChatCompletionMessage{
        				{
        					Role:    openai.ChatMessageRoleSystem,
        					Content: "You are a helpful assistant.",
        				},
        				{
        					Role:    openai.ChatMessageRoleUser,
        					Content: "Hello!",
        				},
        			},
        		},
        	)

        	if err != nil {
        		fmt.Printf("ChatCompletion error: %v", err)
        		return
        	}

        	fmt.Println(resp.Choices[0].Message.Content)
        }
        ```
      </Step>

      <Step title="运行您的代码">
        ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
        go run main.go
        ```

        **示例输出：**

        ```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
        Hello! What can I help you with today?
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>
