Pular para o conteúdo principal

Chat

Create Chat Completion​

POST https://chat.maritaca.ai/api/chat/completions

This endpoint calls the model to generate responses based on specified inputs. Below are the detailed parameters and usage examples.

Request Body​


model string Required​

Default is sabia-4. The model that will generate the response.


messages array Required​

Messages sent to the model. A list of messages is expected, each with "role" (role: system, user, assistant, or tool) and "content" (content of the message). Example:

  • user: "Hello, what is the result of 25 + 27?"
  • assistant: "The result is 52."
System message (object)
  • content (string) Required: The content of the system message.
  • role (string) Required: The role of the message author, in this case, system.
User message (object)
  • content (string) Required: The content of the user message.
  • role (string) Required: The role of the message author, in this case, user.
Assistant message (object)
  • content (string) Required: The content of the assistant's response.
  • role (string) Required: The role of the message author, in this case, assistant.
Tool message (object)
  • content (string) Required: The content of the tool message.
  • role (string) Required: The role of the message author, in this case, tool.

frequency_penalty float or null Optional​

Default is 0. Range is from -2.0 to 2.0. Positive values penalize tokens based on frequency in the conversation, reducing repetition probability.


max_tokens int or null Optional​

Sets an upper limit on the number of tokens generated in the response, controlling the cost for the text generated via the API.


n int or null Optional​

Default is 1. Specifies how many response options should be generated for each input message.


presence_penalty float or null Optional​

Default is 0. Range from -2.0 to 2.0. Increases the probability of new topics in the conversation by penalizing repetitions.


stop array Optional​

List of tokens that, when generated, indicate that the model should stop generating tokens.


stream bool or null Optional​

Default is false. If True, the model will run in streaming mode, where tokens are generated and returned to the client as they are created. If False, the model will operate in batch mode, generating all tokens before returning them to the client.


stream_options object{str: bool} or null Optional​

Options to control streaming behavior, used only if stream=True. Available options are:

  • include_usage: if True, a final chunk will be emitted before the end of the stream containing the request's token count.

temperature float or null Optional​

Default is 0.7. Sampling temperature for generation, with higher values producing more random responses.


top_p float or null Optional​

Default is 0.95. If less than 1, only the top tokens with cumulative probability >= top_p are kept (nucleus sampling). For example, 0.95 means that only the tokens that make up the top 95% of the probability mass are considered when predicting the next token. Nucleus sampling is described in Holtzman et al..


tools array Optional​

A list of tools the model can call. Use this parameter to provide a list of functions for which the model can generate JSON inputs.


web_search bool or null Optional​

Default is false. If true, allows the model to search and read web pages. Web search requires stream: false.


web_search_filters object or null Optional​

Optional filters used when web_search is enabled.

  • allowed_domains (array of strings): Keeps only results from these domains. Maximum 100.
  • blocked_domains (array of strings): Excludes results from these domains. Maximum 100.

When both lists are used, allowed_domains restricts the result set and blocked_domains removes results from that set, taking precedence. Provide domains without a protocol, port, or path. Each domain also includes its subdomains. With the OpenAI SDK, pass web_search and web_search_filters through extra_body.


tool_choice string or object Optional​

Controls which (if any) tool the model calls.

  • "none": the model will not call any tool and will instead generate a message.
  • "auto": the model can choose between generating a message or calling one or more tools.
  • "required": the model must call one or more tools.

Request Example​

import openai

client = openai.OpenAI(
api_key=maritaca_key,
base_url="https://chat.maritaca.ai/api",
)


completion = client.chat.completions.create(
model="sabia-4",
messages= [
{
"role": "system",
"content": "You are a travel assistant specialized in providing information on tourist destinations, hotels, restaurants, and local activities."
},
{
"role": "user",
"content": "I am planning a trip to Bahia. Could you recommend a tourist spot?"
}
]

)

print(completion.choices[0].message)