---
title: "POST /threads/runs"
method: POST
path: "/threads/runs"
---

# POST /threads/runs

`POST /threads/runs`

Creates a new agent thread and immediately starts a run using that new thread.

## Query parameters

- `api-version` string, required

## Request body

- CreateAndRunThreadOptions — The details used when creating and immediately running a new agent thread.
  - `assistant_id` string, required — The ID of the agent for which the thread should be created.
  - `thread` AgentThreadCreationOptions — The details used to create a new agent thread.
    - `messages` ThreadMessageOptions[] — The initial messages to associate with the new thread.
      - `role` 'user' | 'assistant', required — The possible values for roles attributed to messages in a thread.
      - `content` unknown, required
      - `attachments` MessageAttachment[], nullable — A list of files attached to the message, and the tools they should be added to.
        - `file_id` string — The ID of the file to attach to the message.
        - `data_source` VectorStoreDataSource — The structure, containing Azure asset URI path and the asset type of the file used as a data source for the enterprise file search.
          - `uri` string, required — Asset URI.
          - `type` 'uri_asset' | 'id_asset', required — Type of vector storage asset. Asset type may be a uri_asset, in this case it should contain asset URI ID, in the case of id_asset it should contain the data ID.
        - `tools` MessageAttachmentToolDefinition[], required — The tools to add to this file.
          - unknown
      - `metadata` object, nullable — A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
    - `tool_resources` ToolResources — A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
      - `code_interpreter` CodeInterpreterToolResource — A set of resources that are used by the `code_interpreter` tool.
        - `file_ids` string[] — A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool.
        - `data_sources` VectorStoreDataSource[] — The data sources to be used. This option is mutually exclusive with the `fileIds` property.
          - `uri` string, required — Asset URI.
          - `type` 'uri_asset' | 'id_asset', required — Type of vector storage asset. Asset type may be a uri_asset, in this case it should contain asset URI ID, in the case of id_asset it should contain the data ID.
      - `file_search` FileSearchToolResource — A set of resources that are used by the `file_search` tool.
        - `vector_store_ids` string[] — The ID of the vector store attached to this agent. There can be a maximum of 1 vector store attached to the agent.
        - `vector_stores` VectorStoreConfigurations[] — The list of vector store configuration objects from Azure. This list is limited to one element. The only element of this list contains the list of azure asset IDs used by the search tool.
          - `name` string, required — Name
          - `configuration` VectorStoreConfiguration, required — Vector storage configuration is the list of data sources, used when multiple files can be used for the enterprise file search.
            - `data_sources` VectorStoreDataSource[], required — Data sources
              - …
      - `azure_ai_search` AzureAISearchToolResource — A set of index resources used by the `azure_ai_search` tool.
        - `indexes` AISearchIndexResource[] — The indices attached to this agent. There can be a maximum of 1 index resource attached to the agent.
          - `index_connection_id` string — An index connection id in an IndexResource attached to this agent.
          - `index_name` string — The name of an index in an IndexResource attached to this agent.
          - `query_type` 'simple' | 'semantic' | 'vector' | 'vector_simple_hybrid' | 'vector_semantic_hybrid' — Available query types for Azure AI Search tool.
          - `top_k` integer — Number of documents to retrieve from search and present to the model.
          - `filter` string — filter string for search resource.
          - `index_asset_id` string — Index asset id for search resource.
    - `metadata` object, nullable — A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
  - `model` string, nullable — The overridden model that the agent should use to run the thread.
  - `instructions` string, nullable — The overridden system instructions the agent should use to run the thread.
  - `tools` ToolDefinition[], nullable — The overridden list of enabled tools the agent should use to run the thread.
    - `type` string, required — The object type.
  - `tool_resources` ToolResources — A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
    - `code_interpreter` CodeInterpreterToolResource — A set of resources that are used by the `code_interpreter` tool.
      - `file_ids` string[] — A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool.
      - `data_sources` VectorStoreDataSource[] — The data sources to be used. This option is mutually exclusive with the `fileIds` property.
        - `uri` string, required — Asset URI.
        - `type` 'uri_asset' | 'id_asset', required — Type of vector storage asset. Asset type may be a uri_asset, in this case it should contain asset URI ID, in the case of id_asset it should contain the data ID.
    - `file_search` FileSearchToolResource — A set of resources that are used by the `file_search` tool.
      - `vector_store_ids` string[] — The ID of the vector store attached to this agent. There can be a maximum of 1 vector store attached to the agent.
      - `vector_stores` VectorStoreConfigurations[] — The list of vector store configuration objects from Azure. This list is limited to one element. The only element of this list contains the list of azure asset IDs used by the search tool.
        - `name` string, required — Name
        - `configuration` VectorStoreConfiguration, required — Vector storage configuration is the list of data sources, used when multiple files can be used for the enterprise file search.
          - `data_sources` VectorStoreDataSource[], required — Data sources
            - `uri` string, required — Asset URI.
            - `type` 'uri_asset' | 'id_asset', required — Type of vector storage asset. Asset type may be a uri_asset, in this case it should contain asset URI ID, in the case of id_asset it should contain the data ID.
    - `azure_ai_search` AzureAISearchToolResource — A set of index resources used by the `azure_ai_search` tool.
      - `indexes` AISearchIndexResource[] — The indices attached to this agent. There can be a maximum of 1 index resource attached to the agent.
        - `index_connection_id` string — An index connection id in an IndexResource attached to this agent.
        - `index_name` string — The name of an index in an IndexResource attached to this agent.
        - `query_type` 'simple' | 'semantic' | 'vector' | 'vector_simple_hybrid' | 'vector_semantic_hybrid' — Available query types for Azure AI Search tool.
        - `top_k` integer — Number of documents to retrieve from search and present to the model.
        - `filter` string — filter string for search resource.
        - `index_asset_id` string — Index asset id for search resource.
  - `stream` boolean — If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message.
  - `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.
  - `top_p` number, float, nullable — An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
  - `max_prompt_tokens` integer, nullable — The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info.
  - `max_completion_tokens` integer, nullable — The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info.
  - `truncation_strategy` TruncationObject — Controls for how a thread will be truncated prior to the run. Use this to control the initial context window of the run.
    - `type` 'auto' | 'last_messages', required — The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the `lastMessages` count most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`.
    - `last_messages` integer, nullable — The number of most recent messages from the thread when constructing the context for the run.
  - `tool_choice` unknown
  - `response_format` unknown
  - `parallel_tool_calls` boolean — If `true` functions will run in parallel during tool use.
  - `metadata` object, nullable — A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.

## Response `200`

Information about the newly created thread run.

- ThreadRun — Data representing a single evaluation run of an agent thread.
  - `id` string, required — The identifier, which can be referenced in API endpoints.
  - `object` 'thread.run', required — The object type, which is always 'thread.run'.
  - `thread_id` string, required — The ID of the thread associated with this run.
  - `assistant_id` string, required — The ID of the agent associated with the thread this run was performed against.
  - `status` 'queued' | 'in_progress' | 'requires_action' | 'cancelling' | 'cancelled' | 'failed' | 'completed' | 'expired', required — Possible values for the status of an agent thread run.
  - `required_action` RequiredAction — An abstract representation of a required action for an agent thread run to continue.
    - `type` string, required — The object type.
  - `last_error` RunError, required — The details of an error as encountered by an agent thread run.
    - `code` string, required — The status for the error.
    - `message` string, required — The human-readable text associated with the error.
  - `model` string, required — The ID of the model to use.
  - `instructions` string, required — The overridden system instructions used for this agent thread run.
  - `tools` ToolDefinition[], required — The overridden enabled tools used for this agent thread run.
    - `type` string, required — The object type.
  - `created_at` integer, required — The Unix timestamp, in seconds, representing when this object was created.
  - `expires_at` integer, nullable, required — The Unix timestamp, in seconds, representing when this item expires.
  - `started_at` integer, nullable, required — The Unix timestamp, in seconds, representing when this item was started.
  - `completed_at` integer, nullable, required — The Unix timestamp, in seconds, representing when this completed.
  - `cancelled_at` integer, nullable, required — The Unix timestamp, in seconds, representing when this was cancelled.
  - `failed_at` integer, nullable, required — The Unix timestamp, in seconds, representing when this failed.
  - `incomplete_details` IncompleteRunDetails, required — Details on why the run is incomplete. Will be `null` if the run is not incomplete.
    - `reason` 'max_completion_tokens' | 'max_prompt_tokens', required — The reason why the run is incomplete. This will point to which specific token limit was reached over the course of the run.
  - `usage` RunCompletionUsage, required — Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.).
    - `completion_tokens` integer, required — Number of completion tokens used over the course of the run.
    - `prompt_tokens` integer, required — Number of prompt tokens used over the course of the run.
    - `total_tokens` integer, required — Total number of tokens used (prompt + completion).
  - `temperature` number, float, nullable — The sampling temperature used for this run. If not set, defaults to 1.
  - `top_p` number, float, nullable — The nucleus sampling value used for this run. If not set, defaults to 1.
  - `max_prompt_tokens` integer, nullable, required — The maximum number of prompt tokens specified to have been used over the course of the run.
  - `max_completion_tokens` integer, nullable, required — The maximum number of completion tokens specified to have been used over the course of the run.
  - `truncation_strategy` TruncationObject, required — Controls for how a thread will be truncated prior to the run. Use this to control the initial context window of the run.
    - `type` 'auto' | 'last_messages', required — The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the `lastMessages` count most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`.
    - `last_messages` integer, nullable — The number of most recent messages from the thread when constructing the context for the run.
  - `tool_choice` unknown, required
  - `response_format` unknown, required
  - `metadata` object, nullable, required — A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
  - `tool_resources` ToolResources — A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
    - `code_interpreter` CodeInterpreterToolResource — A set of resources that are used by the `code_interpreter` tool.
      - `file_ids` string[] — A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files associated with the tool.
      - `data_sources` VectorStoreDataSource[] — The data sources to be used. This option is mutually exclusive with the `fileIds` property.
        - `uri` string, required — Asset URI.
        - `type` 'uri_asset' | 'id_asset', required — Type of vector storage asset. Asset type may be a uri_asset, in this case it should contain asset URI ID, in the case of id_asset it should contain the data ID.
    - `file_search` FileSearchToolResource — A set of resources that are used by the `file_search` tool.
      - `vector_store_ids` string[] — The ID of the vector store attached to this agent. There can be a maximum of 1 vector store attached to the agent.
      - `vector_stores` VectorStoreConfigurations[] — The list of vector store configuration objects from Azure. This list is limited to one element. The only element of this list contains the list of azure asset IDs used by the search tool.
        - `name` string, required — Name
        - `configuration` VectorStoreConfiguration, required — Vector storage configuration is the list of data sources, used when multiple files can be used for the enterprise file search.
          - `data_sources` VectorStoreDataSource[], required — Data sources
            - `uri` string, required — Asset URI.
            - `type` 'uri_asset' | 'id_asset', required — Type of vector storage asset. Asset type may be a uri_asset, in this case it should contain asset URI ID, in the case of id_asset it should contain the data ID.
    - `azure_ai_search` AzureAISearchToolResource — A set of index resources used by the `azure_ai_search` tool.
      - `indexes` AISearchIndexResource[] — The indices attached to this agent. There can be a maximum of 1 index resource attached to the agent.
        - `index_connection_id` string — An index connection id in an IndexResource attached to this agent.
        - `index_name` string — The name of an index in an IndexResource attached to this agent.
        - `query_type` 'simple' | 'semantic' | 'vector' | 'vector_simple_hybrid' | 'vector_semantic_hybrid' — Available query types for Azure AI Search tool.
        - `top_k` integer — Number of documents to retrieve from search and present to the model.
        - `filter` string — filter string for search resource.
        - `index_asset_id` string — Index asset id for search resource.
  - `parallel_tool_calls` boolean, required — Determines if tools can be executed in parallel within the run.

## Other responses

- `default` — An unexpected error response.

---

[API](https://skmtc.net/azure/apis/ai-azure-ai-agents.md) · [All operations](https://skmtc.net/azure/apis/ai-azure-ai-agents/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/azure/ai-azure-ai-agents/versions/de4a99f09829/schema)
