Skip to content

Latest commit

 

History

History
145 lines (107 loc) · 25.4 KB

README.md

File metadata and controls

145 lines (107 loc) · 25.4 KB

Responses

Overview

Stateless Responses API for text, images, reasoning, function calls, and streaming.

Available Operations

create

Create a response.

Generate a model response from text, image, or file inputs. The response can include text, reasoning, and function calls. Set stream to true to receive Server-Sent Events.

For multi-turn conversations, send the full history in input, including prior output items and function results. Responses are not stored. Only client-executed function tools are supported.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY"),
) as mistral:

    res = mistral.responses.create(model="V90", input=[], parallel_tool_calls=True, stream=False, additional_properties={
        "truncation": "disabled",
        "background": False,
        "store": False,
        "top_logprobs": 0,
    })

    with res as event_stream:
        for event in event_stream:
            # handle event
            print(event, flush=True)

Parameters

Parameter Type Required Description
model str ✔️ N/A
input models.CreateResponseRequestInput2 ✔️ N/A
instructions OptionalNullable[str] ➖ N/A
parallel_tool_calls Optional[bool] ➖ N/A
previous_response_id OptionalNullable[Any] ➖ N/A
tools List[models.CreateResponseRequestTool] ➖ N/A
tool_choice Optional[models.CreateResponseRequestToolChoiceUnion] ➖ N/A
reasoning OptionalNullable[models.CreateResponseRequestResponsesSupportedReasoning] ➖ N/A
conversation OptionalNullable[Any] ➖ N/A
prompt OptionalNullable[Any] ➖ N/A
text OptionalNullable[models.CreateResponseRequestResponsesTextConfig] ➖ N/A
stream Optional[bool] ➖ N/A
max_output_tokens OptionalNullable[int] ➖ N/A
temperature OptionalNullable[float] ➖ N/A
top_p OptionalNullable[float] ➖ N/A
metadata Dict[str, str] ➖ N/A
prompt_cache_key OptionalNullable[str] ➖ N/A
max_tool_calls OptionalNullable[int] ➖ N/A
moderation OptionalNullable[Any] ➖ N/A
additional_properties Dict[str, Any] ➖ N/A
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.CreateResponseV1ResponsesPostResponse

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

count_input_tokens

Count response input tokens.

Count the input tokens for a Responses request without generating a response. The count includes the supplied conversation, instructions, and tool definitions.

Use the same input, instructions, and tools that you plan to send when creating a response. For multi-turn conversations, include prior output items and function results in input.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY"),
) as mistral:

    res = mistral.responses.count_input_tokens(model="Corvette", input="<value>", parallel_tool_calls=True, additional_properties={
        "truncation": "disabled",
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
model str ✔️ N/A
input models.CountResponseInputTokensRequestInput2 ✔️ N/A
instructions OptionalNullable[str] ➖ N/A
parallel_tool_calls Optional[bool] ➖ N/A
previous_response_id OptionalNullable[Any] ➖ N/A
tools List[models.CountResponseInputTokensRequestTool] ➖ N/A
tool_choice Optional[models.CountResponseInputTokensRequestToolChoiceUnion] ➖ N/A
reasoning OptionalNullable[models.CountResponseInputTokensRequestResponsesSupportedReasoning] ➖ N/A
conversation OptionalNullable[Any] ➖ N/A
prompt OptionalNullable[Any] ➖ N/A
text OptionalNullable[models.CountResponseInputTokensRequestResponsesTextConfig] ➖ N/A
additional_properties Dict[str, Any] ➖ N/A
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.CountResponseInputTokensResponse

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*