---
title: "Text Generation V2"
method: POST
path: "/v1/text/chatcompletion_v2"
tags: ["Text Generation"]
---

# Text Generation V2

`POST /v1/text/chatcompletion_v2`

## Request

- Base URL: `https://api.minimax.io`
- URL: `https://api.minimax.io/v1/text/chatcompletion_v2`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/minimax/apis/minimax-api-2/docs/v1/text/chatcompletion_v2/post.ts> (a function with typed inputs; its response is checked against the schema)

Generate text using MiniMax models with support for single-turn and multi-turn conversations

## Request body

- ChatCompletionReq
  - `model` 'MiniMax-M1' | 'MiniMax-Text-01', required: Model ID for text generation
  - `messages` Message[], required: List of messages in the conversation
    - `role` 'system' | 'user' | 'assistant', required: Role of the message sender
    - `content` string, required: Content of the message
  - `temperature` number, double: Sampling temperature (0.0 to 1.0)
  - `max_tokens` integer: Maximum number of tokens to generate
  - `stream` boolean: Whether to stream the response
  - `top_p` number, double: Nucleus sampling parameter

## Response `200`

Successful response

- ChatCompletionResp
  - `id` string: Unique identifier for the completion
  - `object` 'chat.completion': Object type
  - `created` integer: Unix timestamp of creation
  - `model` string: Model used for completion
  - `choices` Choice[]: List of completion choices
    - `index` integer: Index of the choice
    - `message` Message
      - `role` 'system' | 'user' | 'assistant', required: Role of the message sender
      - `content` string, required: Content of the message
    - `finish_reason` 'stop' | 'length' | 'content_filter': Reason for completion
  - `usage` Usage
    - `prompt_tokens` integer: Number of tokens in the prompt
    - `completion_tokens` integer: Number of tokens in the completion
    - `total_tokens` integer: Total number of tokens used

## Other responses

- `400`: Bad request
- `401`: Authentication failed
- `500`: Internal server error

---

[API](https://skmtc.dev/minimax/apis/minimax-api-2.md) - [All operations](https://skmtc.dev/minimax/apis/minimax-api-2/llms.txt) - [OpenAPI document](https://skmtc.dev/minimax/apis/minimax-api-2/revisions/b18c2ab45c0e?raw)
