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

# Chat Completions

***

## 💡 快速示例

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(
        api_key="your-api-key",
        base_url="https://api.mountsea.ai/chat"
    )

    # Basic chat
    response = client.chat.completions.create(
        model="gpt-5.1",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Hello!"}
        ]
    )

    print(response.choices[0].message.content)
    ```

    **流式响应：**

    ```python theme={null}
    stream = client.chat.completions.create(
        model="gpt-5.1",
        messages=[{"role": "user", "content": "Tell me a story"}],
        stream=True
    )

    for chunk in stream:
        if chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="")
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import OpenAI from 'openai';

    const client = new OpenAI({
        apiKey: 'your-api-key',
        baseURL: 'https://api.mountsea.ai/chat'
    });

    // Basic chat
    const response = await client.chat.completions.create({
        model: 'gpt-5.1',
        messages: [
            { role: 'system', content: 'You are a helpful assistant.' },
            { role: 'user', content: 'Hello!' }
        ]
    });

    console.log(response.choices[0].message.content);
    ```

    **流式响应：**

    ```javascript theme={null}
    const stream = await client.chat.completions.create({
        model: 'gpt-5.1',
        messages: [{ role: 'user', content: 'Tell me a story' }],
        stream: true
    });

    for await (const chunk of stream) {
        process.stdout.write(chunk.choices[0]?.delta?.content || '');
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    import com.openai.client.OpenAIClient;
    import com.openai.client.okhttp.OpenAIOkHttpClient;
    import com.openai.models.*;

    // Initialize client
    OpenAIClient client = OpenAIOkHttpClient.builder()
        .apiKey("your-api-key")
        .baseUrl("https://api.mountsea.ai/chat")
        .build();

    // Basic chat
    ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
        .model("gpt-5.1")
        .addMessage(ChatCompletionMessageParam.ofSystem(
            SystemMessage.builder().content("You are a helpful assistant.").build()))
        .addMessage(ChatCompletionMessageParam.ofUser(
            UserMessage.builder().content("Hello!").build()))
        .build();

    ChatCompletion response = client.chat().completions().create(params);
    System.out.println(response.choices().get(0).message().content());
    ```

    **流式响应：**

    ```java theme={null}
    ChatCompletionCreateParams streamParams = ChatCompletionCreateParams.builder()
        .model("gpt-5.1")
        .addMessage(ChatCompletionMessageParam.ofUser(
            UserMessage.builder().content("Tell me a story").build()))
        .build();

    client.chat().completions().createStreaming(streamParams)
        .forEach(chunk -> {
            String content = chunk.choices().get(0).delta().content().orElse("");
            System.out.print(content);
        });
    ```

    **Maven 依赖：**

    ```xml theme={null}
    <dependency>
        <groupId>com.openai</groupId>
        <artifactId>openai-java</artifactId>
        <version>0.8.0</version>
    </dependency>
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    package main

    import (
        "context"
        "fmt"
        "github.com/openai/openai-go"
        "github.com/openai/openai-go/option"
    )

    func main() {
        // Initialize client
        client := openai.NewClient(
            option.WithAPIKey("your-api-key"),
            option.WithBaseURL("https://api.mountsea.ai/chat"),
        )

        // Basic chat
        response, _ := client.Chat.Completions.New(context.TODO(),
            openai.ChatCompletionNewParams{
                Model: openai.String("gpt-5.1"),
                Messages: []openai.ChatCompletionMessageParamUnion{
                    openai.SystemMessage("You are a helpful assistant."),
                    openai.UserMessage("Hello!"),
                },
            },
        )

        fmt.Println(response.Choices[0].Message.Content)
    }
    ```

    **流式响应：**

    ```go theme={null}
    stream := client.Chat.Completions.NewStreaming(context.TODO(),
        openai.ChatCompletionNewParams{
            Model: openai.String("gpt-5.1"),
            Messages: []openai.ChatCompletionMessageParamUnion{
                openai.UserMessage("Tell me a story"),
            },
        },
    )

    for stream.Next() {
        chunk := stream.Current()
        fmt.Print(chunk.Choices[0].Delta.Content)
    }
    ```

    **安装：**

    ```bash theme={null}
    go get github.com/openai/openai-go
    ```
  </Tab>
</Tabs>

***

## 📤 响应格式

### 非流式响应

```json theme={null}
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "gpt-5.1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 26,
    "completion_tokens": 10,
    "total_tokens": 36
  }
}
```

### 流式响应 (SSE)

```
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"role":"assistant"}}]}

data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"Hello"}}]}

data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"!"}}]}

data: {"id":"chatcmpl-xxx","choices":[{"delta":{},"finish_reason":"stop"}]}

data: [DONE]
```

***

## 🔧 API 参考

<Info>
  以下交互式 API 表单由 OpenAPI 规范自动生成。所有可用模型均显示在 `model` 下拉菜单中。
</Info>


## OpenAPI

````yaml POST /chat/chat/completions
openapi: 3.0.0
info:
  title: Chat AI
  description: API documentation for Chat AI
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.mountsea.ai
    description: API Gateway
security: []
tags:
  - name: chat
    description: ''
paths:
  /chat/chat/completions:
    post:
      tags:
        - Chat - OpenAI Compatible
      summary: 聊天完成 (OpenAI 兼容)
      operationId: ApiPublicController_chatCompletions
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequestDto'
      responses:
        '200':
          description: 成功
      security:
        - bearerAuth: []
components:
  schemas:
    ChatCompletionRequestDto:
      type: object
      properties:
        model:
          enum:
            - gpt-5.1
            - gpt-5.1-all
            - gpt-5.1-thinking
            - gpt-5.1-thinking-all
            - gpt-5.2
            - gpt-5.3
            - gpt-5.3-codex
            - gpt-5.4
            - gemini-3-pro
            - gemini-2.5-pro
            - gemini-2.5-flash
            - gemini-3-flash
            - gemini-3.1-pro
            - claude-4.5
            - claude-opus-4-6
            - claude-haiku-4-5-20251001
            - claude-sonnet-4-6
            - claude-opus-4-7
          type: string
          description: 模型名称
          example: gpt-5.1
        messages:
          description: 消息列表
          example:
            - role: system
              content: You are a helpful assistant.
            - role: user
              content: Hello!
          type: array
          items:
            type: object
        stream:
          type: boolean
          description: 是否流式输出
          example: false
        temperature:
          type: number
          nullable: true
          description: 温度 (0-2)
          example: 1
        max_tokens:
          type: number
          nullable: true
          description: 最大 token 数
          example: 1000
        max_completion_tokens:
          type: number
          nullable: true
          description: 最大补全 token 数 (新版参数)
          example: 1000
        top_p:
          type: number
          nullable: true
          description: Top P
          example: 1
        frequency_penalty:
          type: number
          nullable: true
          description: 频率惩罚 (-2.0 到 2.0)
          example: 0
        presence_penalty:
          type: number
          nullable: true
          description: 存在惩罚 (-2.0 到 2.0)
          example: 0
        stop:
          type: object
          description: 停止序列
        'n':
          type: number
          nullable: true
          description: 生成数量
          example: 1
        seed:
          type: number
          nullable: true
          description: 随机种子
          example: 12345
        user:
          type: string
          description: 用户标识
        tools:
          description: 工具列表 (Function Calling)
          type: array
          items:
            type: object
        tool_choice:
          type: object
          description: 工具选择策略
        response_format:
          type: object
          description: 响应格式
        logprobs:
          type: boolean
          nullable: true
          description: 是否返回 logprobs
          example: false
        top_logprobs:
          type: number
          nullable: true
          description: top logprobs 数量
          example: 5
        logit_bias:
          type: object
          nullable: true
          description: logit 偏置
        parallel_tool_calls:
          type: boolean
          description: 并行工具调用
          example: true
      required:
        - model
        - messages
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````