---
title: "Send Completion Message"
method: POST
path: "/completion-messages"
tags: ["Completion Messages"]
---

# Send Completion Message

`POST /completion-messages`

**Available for**: Text Generator apps.

Sends a request to a text-generation app and returns the generated text.

## Request body

- CompletionRequest — unresolved $ref

## Response `200`

Successful response. The content type and structure depend on the `response_mode` parameter in the request.

- If `response_mode` is `blocking`, returns `application/json` with a `CompletionResponse` object.
- If `response_mode` is `streaming`, returns `text/event-stream` with a stream of `ChunkCompletionEvent` objects.

- CompletionResponse
  - `event` string — Event type, fixed as `message`.
  - `task_id` string, uuid — Task ID for request tracking and the [Stop Completion Message Generation](/en/api-reference/completion-messages/stop-completion-message-generation) API.
  - `id` string, uuid — Unique ID of this response event.
  - `message_id` string, uuid — Unique message ID. Use this as the `message_id` parameter when calling feedback or suggested questions endpoints.
  - `mode` string — App mode, fixed as `completion`.
  - `answer` string — Complete response content.
  - `metadata` object — Metadata including usage and retriever resources.
    - `usage` Usage — Model usage information.
      - `prompt_tokens` integer — Number of tokens in the prompt.
      - `prompt_unit_price` string, decimal — Unit price per prompt token.
      - `prompt_price_unit` string, decimal — Price unit for prompt tokens.
      - `prompt_price` string, decimal — Total price for prompt tokens.
      - `completion_tokens` integer — Number of tokens in the completion.
      - `completion_unit_price` string, decimal — Unit price per completion token.
      - `completion_price_unit` string, decimal — Price unit for completion tokens.
      - `completion_price` string, decimal — Total price for completion tokens.
      - `total_tokens` integer — Total number of tokens used.
      - `total_price` string, decimal — Total price for all tokens.
      - `currency` string — Currency for pricing.
      - `latency` number, double — Latency in seconds.
    - `retriever_resources` RetrieverResource[] — List of retriever resources used.
      - `id` string, uuid — Unique ID of the retriever resource.
      - `message_id` string, uuid — ID of the message this resource belongs to.
      - `position` integer — Position of the resource in the list.
      - `dataset_id` string, uuid — ID of the knowledge base.
      - `dataset_name` string — Name of the knowledge base.
      - `document_id` string, uuid — ID of the document.
      - `document_name` string — Name of the document.
      - `data_source_type` string — Type of the data source.
      - `segment_id` string, uuid — ID of the specific chunk within the document.
      - `score` number, float — Similarity score of the resource.
      - `hit_count` integer — Number of times this chunk was hit.
      - `word_count` integer — Word count of the chunk.
      - `segment_position` integer — Position of the chunk within the document.
      - `index_node_hash` string — Hash of the index node.
      - `content` string — Content snippet from the resource.
      - `summary` string, nullable — Summary of the chunk content.
      - `created_at` integer — Creation timestamp (Unix epoch seconds).
  - `created_at` integer — Message creation timestamp (Unix epoch seconds).

## Other responses

- `400` — - `app_unavailable` : App unavailable or misconfigured. - `provider_not_initialize` : No valid model provider credentials found. - `provider_quota_exceeded` : Model provider quota exhausted. - `model_currently_not_support` : Current model unavailable. - `completion_request_error` : Text generation failed. - `invalid_param` : The required `user` field is missing.
- `429` — `too_many_requests` : Too many concurrent requests for this app.
- `500` — `internal_server_error` : Internal server error.

---

[API](https://skmtc.dev/langgenius/apis/dify-service-api.md) · [All operations](https://skmtc.dev/langgenius/apis/dify-service-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/langgenius/dify-service-api/revisions/9c8c06aed889/schema)
