---
title: "Create message"
method: POST
path: "/api/message"
tags: ["Message"]
---

# Create message

`POST /api/message`

Create message. Messages are attached to topics in order to coordinate memory of gen-AI chat sessions.Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.

## Headers

- `TR-Dataset` string, uuid, required

## Request body

- CreateMessageReqPayload
  - `audio_input` string, nullable — The base64 encoded audio input of the user message to attach to the topic and then generate an assistant message in response to.
  - `concat_user_messages_query` boolean, nullable — If concat user messages query is set to true, all of the user messages in the topic will be concatenated together and used as the search query. If not specified, this defaults to false. Default is false.
  - `context_options` ContextOptions — Context options to use for the completion. If not specified, all options will default to false.
    - `include_links` boolean, nullable — Include links in the context. If not specified, this defaults to false.
  - `currency` string, nullable — The currency to use for the completion. If not specified, this defaults to "USD".
  - `filters` ChunkFilter — ChunkFilter is a JSON object which can be used to filter chunks. This is useful for when you want to filter chunks by arbitrary metadata. Unlike with tag filtering, there is a performance hit for filtering on metadata.
    - `must` ConditionType[], nullable — All of these field conditions have to match for the chunk to be included in the result set.
      - union — Filters can be constructed using either fields on the chunk objects, ids or tracking ids of chunks, and finally ids or tracking ids of groups.
        - FieldCondition — FieldCondition is a JSON object which can be used to filter chunks by a field. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
          - `boolean` boolean, nullable — Boolean is a true false value for a field. This only works for boolean fields. You can specify this if you want values to be true or false.
          - `date_range` DateRange — DateRange is a JSON object which can be used to filter chunks by a range of dates. This leverages the time_stamp field on chunks in your dataset. You can specify this if you want values in a certain range. You must provide ISO 8601 combined date and time without timezone.
            - `gt` string, nullable
            - `gte` string, nullable
            - `lt` string, nullable
            - `lte` string, nullable
          - `field` string, required — Field is the name of the field to filter on. Commonly used fields are `timestamp`, `link`, `tag_set`, `location`, `num_value`, `group_ids`, and `group_tracking_ids`. The field value will be used to check for an exact substring match on the metadata values for each existing chunk. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
          - `geo_bounding_box` LocationBoundingBox
            - `bottom_right` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `top_left` GeoInfo, required — Location that you want to use as the center of the search.
              - …
          - `geo_polygon` LocationPolygon
            - `exterior` GeoInfo[], required
              - …
            - `interior` array[], nullable
              - …
          - `geo_radius` LocationRadius
            - `center` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `radius` number, double, required
          - `match_all` MatchCondition[], nullable — Match all lets you pass in an array of values that will return results if all of the items match. The match value will be used to check for an exact substring match on the metadata values for each existing chunk. If both match_all and match_any are provided, the match_any condition will be used.
            - union
              - …
          - `match_any` MatchCondition[], nullable — Match any lets you pass in an array of values that will return results if any of the items match. The match value will be used to check for an exact substring match on the metadata values for each existing chunk. If both match_all and match_any are provided, the match_any condition will be used.
            - union
              - …
          - `range` Range
            - `gt` union
              - …
            - `gte` union
              - …
            - `lt` union
              - …
            - `lte` union
              - …
        - HasChunkIDCondition — HasChunkIDCondition is a JSON object which can be used to filter chunks by their ids or tracking ids. This is useful for when you want to filter chunks by their ids or tracking ids.
          - `ids` string[], nullable — Ids of the chunks to apply a match_any condition with. Only chunks with one of these ids will be returned.
          - `tracking_ids` string[], nullable — Tracking ids of the chunks to apply a match_any condition with. Only chunks with one of these tracking ids will be returned.
    - `must_not` ConditionType[], nullable — None of these field conditions can match for the chunk to be included in the result set.
      - union — Filters can be constructed using either fields on the chunk objects, ids or tracking ids of chunks, and finally ids or tracking ids of groups.
        - FieldCondition — FieldCondition is a JSON object which can be used to filter chunks by a field. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
          - `boolean` boolean, nullable — Boolean is a true false value for a field. This only works for boolean fields. You can specify this if you want values to be true or false.
          - `date_range` DateRange — DateRange is a JSON object which can be used to filter chunks by a range of dates. This leverages the time_stamp field on chunks in your dataset. You can specify this if you want values in a certain range. You must provide ISO 8601 combined date and time without timezone.
            - `gt` string, nullable
            - `gte` string, nullable
            - `lt` string, nullable
            - `lte` string, nullable
          - `field` string, required — Field is the name of the field to filter on. Commonly used fields are `timestamp`, `link`, `tag_set`, `location`, `num_value`, `group_ids`, and `group_tracking_ids`. The field value will be used to check for an exact substring match on the metadata values for each existing chunk. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
          - `geo_bounding_box` LocationBoundingBox
            - `bottom_right` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `top_left` GeoInfo, required — Location that you want to use as the center of the search.
              - …
          - `geo_polygon` LocationPolygon
            - `exterior` GeoInfo[], required
              - …
            - `interior` array[], nullable
              - …
          - `geo_radius` LocationRadius
            - `center` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `radius` number, double, required
          - `match_all` MatchCondition[], nullable — Match all lets you pass in an array of values that will return results if all of the items match. The match value will be used to check for an exact substring match on the metadata values for each existing chunk. If both match_all and match_any are provided, the match_any condition will be used.
            - union
              - …
          - `match_any` MatchCondition[], nullable — Match any lets you pass in an array of values that will return results if any of the items match. The match value will be used to check for an exact substring match on the metadata values for each existing chunk. If both match_all and match_any are provided, the match_any condition will be used.
            - union
              - …
          - `range` Range
            - `gt` union
              - …
            - `gte` union
              - …
            - `lt` union
              - …
            - `lte` union
              - …
        - HasChunkIDCondition — HasChunkIDCondition is a JSON object which can be used to filter chunks by their ids or tracking ids. This is useful for when you want to filter chunks by their ids or tracking ids.
          - `ids` string[], nullable — Ids of the chunks to apply a match_any condition with. Only chunks with one of these ids will be returned.
          - `tracking_ids` string[], nullable — Tracking ids of the chunks to apply a match_any condition with. Only chunks with one of these tracking ids will be returned.
    - `should` ConditionType[], nullable — Only one of these field conditions has to match for the chunk to be included in the result set.
      - union — Filters can be constructed using either fields on the chunk objects, ids or tracking ids of chunks, and finally ids or tracking ids of groups.
        - FieldCondition — FieldCondition is a JSON object which can be used to filter chunks by a field. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
          - `boolean` boolean, nullable — Boolean is a true false value for a field. This only works for boolean fields. You can specify this if you want values to be true or false.
          - `date_range` DateRange — DateRange is a JSON object which can be used to filter chunks by a range of dates. This leverages the time_stamp field on chunks in your dataset. You can specify this if you want values in a certain range. You must provide ISO 8601 combined date and time without timezone.
            - `gt` string, nullable
            - `gte` string, nullable
            - `lt` string, nullable
            - `lte` string, nullable
          - `field` string, required — Field is the name of the field to filter on. Commonly used fields are `timestamp`, `link`, `tag_set`, `location`, `num_value`, `group_ids`, and `group_tracking_ids`. The field value will be used to check for an exact substring match on the metadata values for each existing chunk. This is useful for when you want to filter chunks by arbitrary metadata. To access fields inside of the metadata that you provide with the card, prefix the field name with `metadata.`.
          - `geo_bounding_box` LocationBoundingBox
            - `bottom_right` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `top_left` GeoInfo, required — Location that you want to use as the center of the search.
              - …
          - `geo_polygon` LocationPolygon
            - `exterior` GeoInfo[], required
              - …
            - `interior` array[], nullable
              - …
          - `geo_radius` LocationRadius
            - `center` GeoInfo, required — Location that you want to use as the center of the search.
              - …
            - `radius` number, double, required
          - `match_all` MatchCondition[], nullable — Match all lets you pass in an array of values that will return results if all of the items match. The match value will be used to check for an exact substring match on the metadata values for each existing chunk. If both match_all and match_any are provided, the match_any condition will be used.
            - union
              - …
          - `match_any` MatchCondition[], nullable — Match any lets you pass in an array of values that will return results if any of the items match. The match value will be used to check for an exact substring match on the metadata values for each existing chunk. If both match_all and match_any are provided, the match_any condition will be used.
            - union
              - …
          - `range` Range
            - `gt` union
              - …
            - `gte` union
              - …
            - `lt` union
              - …
            - `lte` union
              - …
        - HasChunkIDCondition — HasChunkIDCondition is a JSON object which can be used to filter chunks by their ids or tracking ids. This is useful for when you want to filter chunks by their ids or tracking ids.
          - `ids` string[], nullable — Ids of the chunks to apply a match_any condition with. Only chunks with one of these ids will be returned.
          - `tracking_ids` string[], nullable — Tracking ids of the chunks to apply a match_any condition with. Only chunks with one of these tracking ids will be returned.
  - `highlight_options` HighlightOptions — Highlight Options lets you specify different methods to highlight the chunks in the result set. If not specified, this defaults to the score of the chunks.
    - `highlight_delimiters` string[], nullable — Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"]. These are the characters that will be used to split the chunk_html into splits for highlighting. These are the characters that will be used to split the chunk_html into splits for highlighting.
    - `highlight_max_length` integer, nullable — Set highlight_max_length to control the maximum number of tokens (typically whitespace separated strings, but sometimes also word stems) which can be present within a single highlight. If not specified, this defaults to 8. This is useful to shorten large splits which may have low scores due to length compared to the query. Set to something very large like 100 to highlight entire splits.
    - `highlight_max_num` integer, nullable — Set highlight_max_num to control the maximum number of highlights per chunk. If not specified, this defaults to 3. It may be less than 3 if no snippets score above the highlight_threshold.
    - `highlight_results` boolean, nullable — Set highlight_results to false for a slight latency improvement (1-10ms). If not specified, this defaults to true. This will add `<mark><b>` tags to the chunk_html of the chunks to highlight matching splits and return the highlights on each scored chunk in the response.
    - `highlight_strategy` 'exactmatch' | 'v1'
    - `highlight_threshold` number, double, nullable — Set highlight_threshold to a lower or higher value to adjust the sensitivity of the highlights applied to the chunk html. If not specified, this defaults to 0.8. The range is 0.0 to 1.0.
    - `highlight_window` integer, nullable — Set highlight_window to a number to control the amount of words that are returned around the matched phrases. If not specified, this defaults to 0. This is useful for when you want to show more context around the matched words. When specified, window/2 whitespace separated words are added before and after each highlight in the response's highlights array. If an extended highlight overlaps with another highlight, the overlapping words are only included once. This parameter can be overriden to respect the highlight_max_length param.
    - `post_tag` string, nullable — Custom html tag which should appear after highlights. If not specified, this defaults to '</mark></b>'.
    - `pre_tag` string, nullable — Custom html tag which should appear before highlights. If not specified, this defaults to '<mark><b>'.
  - `image_urls` string[], nullable — The URL of the image(s) to attach to the message.
  - `llm_options` LLMOptions — LLM options to use for the completion. If not specified, this defaults to the dataset's LLM options.
    - `completion_first` boolean, nullable — Completion first decides whether the stream should contain the stream of the completion response or the chunks first. Default is false. Keep in mind that || is used to separate the chunks from the completion response. If || is in the completion then you may want to split on ||{ instead.
    - `frequency_penalty` number, float, nullable — Frequency penalty is a number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. Default is 0.7.
    - `image_config` ImageConfig — Configuration for sending images to the llm
      - `images_per_chunk` integer, nullable — The number of Images to send to the llm per chunk that is fetched more images may slow down llm inference time. default: 5
      - `use_images` boolean, nullable — This sends images to the llm if chunk_metadata.image_urls has some value, the call will error if the model is not a vision LLM model. default: false
    - `max_tokens` integer, nullable — The maximum number of tokens to generate in the chat completion. Default is None.
    - `presence_penalty` number, float, nullable — Presence penalty is a number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. Default is 0.7.
    - `stop_tokens` string[], nullable — Stop tokens are up to 4 sequences where the API will stop generating further tokens. Default is None.
    - `stream_response` boolean, nullable — Whether or not to stream the response. If this is set to true or not included, the response will be a stream. If this is set to false, the response will be a normal JSON response. Default is true.
    - `system_prompt` string, nullable — Optionally, override the system prompt in dataset server settings.
    - `temperature` number, float, nullable — What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Default is 0.5.
  - `metadata` unknown
  - `model` string, nullable — Model name to use for the completion. If not specified, this defaults to the dataset's model.
  - `new_message_content` string, nullable — The content of the user message to attach to the topic and then generate an assistant message in response to.
  - `no_result_message` string, nullable — No result message for when there are no chunks found above the score threshold.
  - `number_of_messages_to_include` integer, nullable — Number of messages to include in the context window. If not specified, this defaults to 10.
  - `only_include_docs_used` boolean, nullable — Only include docs used is a boolean that indicates whether or not to only include the docs that were used in the completion. If true, the completion will only include the docs that were used in the completion. If false, the completion will include all of the docs.
  - `page_size` integer, nullable — Page size is the number of chunks to fetch during RAG. If 0, then no search will be performed. If specified, this will override the N retrievals to include in the dataset configuration. Default is None.
  - `rag_context` string, nullable — Overrides what the way chunks are placed into the context window
  - `remove_stop_words` boolean, nullable — If true, stop words (specified in server/src/stop-words.txt in the git repo) will be removed. Queries that are entirely stop words will be preserved.
  - `score_threshold` number, float, nullable — Set score_threshold to a float to filter out chunks with a score below the threshold. This threshold applies before weight and bias modifications. If not specified, this defaults to 0.0.
  - `search_query` string, nullable — Query is the search query. This can be any string. The search_query will be used to create a dense embedding vector and/or sparse vector which will be used to find the result set. If not specified, will default to the last user message or HyDE if HyDE is enabled in the dataset configuration. Default is None.
  - `search_type` 'fulltext' | 'semantic' | 'hybrid' | 'bm25'
  - `sort_options` SortOptions — Sort Options lets you specify different methods to rerank the chunks in the result set. If not specified, this defaults to the score of the chunks.
    - `location_bias` GeoInfoWithBias — Location bias lets you rank your results by distance from a location. If not specified, this has no effect. Bias allows you to determine how much of an effect the location of chunks will have on the search results. If not specified, this defaults to 0.0. We recommend setting this to 1.0 for a gentle reranking of the results, >3.0 for a strong reranking of the results.
      - `bias` number, double, required — Bias lets you specify how much of an effect the location of chunks will have on the search results. If not specified, this defaults to 0.0. We recommend setting this to 1.0 for a gentle reranking of the results, >3.0 for a strong reranking of the results.
      - `location` GeoInfo, required — Location that you want to use as the center of the search.
        - `lat` union, required
          - integer
          - number, double
        - `lon` union, required
          - integer
          - number, double
    - `mmr` MmrOptions — MMR Options lets you specify different methods to rerank the chunks in the result set using Maximal Marginal Relevance. If not specified, this defaults to the score of the chunks.
      - `mmr_lambda` number, float, nullable — Set mmr_lambda to a value between 0.0 and 1.0 to control the tradeoff between relevance and diversity. Closer to 1.0 will give more diverse results, closer to 0.0 will give more relevant results. If not specified, this defaults to 0.5.
      - `use_mmr` boolean, required — Set use_mmr to true to use the Maximal Marginal Relevance algorithm to rerank the results.
    - `recency_bias` number, float, nullable — Recency Bias lets you determine how much of an effect the recency of chunks will have on the search results. If not specified, this defaults to 0.0. We recommend setting this to 1.0 for a gentle reranking of the results, >3.0 for a strong reranking of the results.
    - `sort_by` union — Sort by lets you specify a method to sort the results by. If not specified, this defaults to the score of the chunks. If specified, this can be any key in the chunk metadata. This key must be a numeric value within the payload.
      - SortByField
        - `direction` 'desc' | 'asc'
        - `field` string, required — Field to sort by. This has to be a numeric field with a Qdrant `Range` index on it. i.e. num_value and timestamp
        - `prefetch_amount` integer, nullable — How many results to pull in before the sort
      - SortBySearchType
        - `prefetch_amount` integer, nullable — How many results to pull in before the rerabj
        - `rerank_query` string, nullable — Query to use for prefetching defaults to the search query
        - `rerank_type` 'semantic' | 'fulltext' | 'bm25' | 'cross_encoder', required
    - `tag_weights` object, nullable — Tag weights is a JSON object which can be used to boost the ranking of chunks with certain tags. This is useful for when you want to be able to bias towards chunks with a certain tag on the fly. The keys are the tag names and the values are the weights.
    - `use_weights` boolean, nullable — Set use_weights to true to use the weights of the chunks in the result set in order to sort them. If not specified, this defaults to true.
  - `topic_id` string, uuid, required — The ID of the topic to attach the message to.
  - `typo_options` TypoOptions — Typo Options lets you specify different methods to correct typos in the query. If not specified, typos will not be corrected.
    - `correct_typos` boolean, nullable — Set correct_typos to true to correct typos in the query. If not specified, this defaults to false.
    - `disable_on_word` string[], nullable — Words that should not be corrected. If not specified, this defaults to an empty list.
    - `one_typo_word_range` TypoRange — The TypoRange struct is used to specify the range of which the query will be corrected if it has a typo.
      - `max` integer, nullable — The maximum number of characters that the query will be corrected if it has a typo. If not specified, this defaults to 8.
      - `min` integer, required — The minimum number of characters that the query will be corrected if it has a typo. If not specified, this defaults to 5.
    - `prioritize_domain_specifc_words` boolean, nullable — Auto-require non-english words present in the dataset to exist in each results chunk_html text. If not specified, this defaults to true.
    - `two_typo_word_range` TypoRange — The TypoRange struct is used to specify the range of which the query will be corrected if it has a typo.
      - `max` integer, nullable — The maximum number of characters that the query will be corrected if it has a typo. If not specified, this defaults to 8.
      - `min` integer, required — The minimum number of characters that the query will be corrected if it has a typo. If not specified, this defaults to 5.
  - `use_agentic_search` boolean, nullable — If true, the search will be conducted using llm tool calling. If not specified, this defaults to false.
  - `use_group_search` boolean, nullable — If use_group_search is set to true, the search will be conducted using the `search_over_groups` api. If not specified, this defaults to false.
  - `use_quote_negated_terms` boolean, nullable — If true, quoted and - prefixed words will be parsed from the queries and used as required and negated words respectively. Default is false.
  - `user_id` string, nullable — The user_id is the id of the user who is making the request. This is used to track user interactions with the RAG results.

## Response `200`

This will be a JSON response of a string containing the LLM's generated inference. Response if not streaming.

## Other responses

- `400` — Service error relating to getting a chat completion

---

[API](https://skmtc.net/devflowinc/apis/trieve-api.md) · [All operations](https://skmtc.net/devflowinc/apis/trieve-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/devflowinc/trieve-api/revisions/84583e7c9fc1/schema)
