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

# chat completions

> chat completions

## Maven

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

## Normal Request Example

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    @Test
    void clientOpenClientTest() {
        OpenAIClient client = OpenAIOkHttpClient.builder()
                .apiKey(apiKey) // Your access key
                .baseUrl("https://ai.pmock.com/api/ai/chat")
                .build();

        ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                .model("gpt-5.2")
                .addMessage(ChatCompletionMessageParam.ofSystem(
                        ChatCompletionSystemMessageParam.builder().content("You are a helpful assistant.").build()))
                .addMessage(ChatCompletionMessageParam.ofUser(
                        ChatCompletionUserMessageParam.builder().content("Hello!").build()))
                .build();

        ChatCompletion chatCompletion = client.chat().completions().create(params);
        System.out.println(chatCompletion.choices().get(0).message().content());
    }
    ```
  </Tab>
</Tabs>

## Normal Response

```json theme={null}
{
	"id": "chatcmpl-xxx",
	"object": "chat.completion",
	"created": 1768810259,
	"model": "gpt-5.1",
	"choices": [
		{
			"index": 0,
			"message": {
				"role": "assistant",
				"content": "Hey! How's it going?"
			},
			"finish_reason": "stop"
		}
	],
	"usage": {
		"prompt_tokens": 0,
		"completion_tokens": 0,
		"total_tokens": 0,
		"prompt_tokens_details": {
			"text_tokens": 0
		},
		"completion_tokens_details": {
			"content_tokens": 0
		}
	}
}
```

## Stream Response

<Tabs>
  <Tab title="Java">
    ```java theme={null}
        @Test
    void streamClientOpenClientTest() {
        OpenAIClient client = OpenAIOkHttpClient.builder()
                .apiKey(apiKey) // Your access key
                .baseUrl("https://ai.pmock.com/api/ai/chat")
                .build();

        ChatCompletionCreateParams streamParams = ChatCompletionCreateParams.builder()
                .model("gpt-5.2")
                .addMessage(ChatCompletionMessageParam.ofSystem(
                        ChatCompletionSystemMessageParam.builder().content("You are a helpful assistant.").build()))
                .addMessage(ChatCompletionMessageParam.ofUser(
                        ChatCompletionUserMessageParam.builder().content("Hello!").build()))
                .build();

        try (StreamResponse<ChatCompletionChunk> streaming = client.chat().completions().createStreaming(streamParams)) {
            streaming.stream().forEach(chunk -> {
                if (!chunk.choices().isEmpty()) {
                    String content = chunk.choices().get(0).delta().content().orElse("");
                    System.out.print(content);
                }
            });
        }
    }
    ```
  </Tab>
</Tabs>

```text theme={null}
data: {"created":1768823313,"model":"gpt-5.1","id":"chatcmpl-xxx","choices":[{"delta":{"content":"?"},"index":0}],"object":"chat.completion.chunk"}
data: {"created":1768823313,"model":"gpt-5.1","id":"chatcmpl-xxx","choices":[{"delta":{},"index":0}],"object":"chat.completion.chunk"}
data: {"created":1768823313,"model":"gpt-5.1","id":"chatcmpl-xxx","choices":[{"delta":{},"finish_reason":"stop","index":0}],"object":"chat.completion.chunk"}
data: {"created":1768823316,"usage":{"completion_tokens":0,"completion_tokens_details":{},"prompt_tokens":0,"prompt_tokens_details":{},"total_tokens":0},"model":"gpt-5.1","id":"chatcmpl-xxx","choices":[{"delta":{},"index":0}],"object":"chat.completion.chunk"}
data: [DONE]
```


## OpenAPI

````yaml post /ai/chat/chat/completions
openapi: 3.1.0
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: https://ai.pmock.com/api
    description: Generated server url
security: []
tags:
  - name: 开放-百度视频生成
    description: 开放-百度视频生成
  - name: 开放-Grok开放接口
    description: 开放-Grok开放接口
  - name: 开放-Gemini开放接口
    description: 开放-Gemini开放接口
  - name: 开放-AI对话开放接口
    description: 开放-AI对话开放接口
  - name: 开放-Sora2开放接口
    description: 开放-Sora2开放接口
  - name: 开放-模型列表接口
    description: 开放-模型列表接口
  - name: 开放-OpenAi开放接口
    description: 开放-OpenAi开放接口
  - name: 开放-业务相关接口
    description: 开放-业务相关接口
  - name: 开放-任务开放接口
    description: 开放-任务开放接口
paths:
  /ai/chat/chat/completions:
    post:
      tags:
        - 开放-AI对话开放接口
      summary: chat completions
      description: chat completions
      operationId: chatChatCompletions
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionsDTO'
        required: true
      responses:
        '200':
          description: OK
          content:
            '*/*':
              schema:
                type: object
components:
  schemas:
    ChatCompletionsDTO:
      type: object
      properties:
        messages:
          type: array
          description: messages
          items: {}
          minItems: 1
        model:
          type: string
          description: >-
            model, You can view the list of supported models through the
            interface `/ai/chat/models`
          enum:
            - gpt-5.4
            - gpt-5.5
            - claude-opus-4-6
            - claude-opus-4-7
            - claude-opus-4-8
        stream:
          type: boolean
          default: false
          description: streaming output
        temperature:
          type: number
          format: double
          description: Temperature (0-2)
        maxTokens:
          type: integer
          format: int32
          description: Maximum token count
        maxCompletionTokens:
          type: integer
          format: int32
          description: Maximum number of completed tokens
        topP:
          type: number
          format: double
          description: top P
        frequencyPenalty:
          type: number
          format: double
          description: frequency penalty(-2.0 to 2.0)
        presencePenalty:
          type: number
          format: double
          description: presence penalty(-2.0 to 2.0)
        stop:
          description: Stop sequence
        'n':
          type: integer
          format: int32
          description: Generated Quantity
        seed:
          type: integer
          format: int32
          description: random seed
        user:
          type: string
          description: user
        tools:
          type: array
          description: Tool List (Function Calling)
          items: {}
        toolChoice:
          description: Tool selection strategy
        responseFormat:
          description: Response format
        logprobs:
          type: boolean
          description: logprobs
        topLogprobs:
          type: integer
          format: int32
          description: top logprobs
        logitBias:
          description: logit bias
        parallelToolCalls:
          type: boolean
          description: parallel tool calls
      required:
        - messages
        - model

````