Skip to main content

Mira API — Chat Completion

In this tutorial we'll get you up and running with the chat-completion features of the Mira API.

We do not cover here suggested prompts for potential use cases. Check out the prompt library in the Meltwater application for prompt ideas.

Before you start

To run through this tutorial, you will need:

  • Your Meltwater API token
  • Access to Mira API

Chat completion endpoint

The API supports chat completion in both streaming and non-streaming mode through the POST /v3/mira/chat endpoint.

Parameters for the endpoint include:

  • user_prompt - The prompt for completion e.g. "What were the top stories for Adidas last week?"
  • stream - true for streaming mode, false for non-streaming mode
  • thread_id - (optional) if not provided the request will start a new conversation thread; if provided the context of the existing thread you reference will be included as context for the chat completion
  • company_id - (optional) Query parameter. The ID of the company to access. If not provided, your default company will be used. See working with multiple companies for more details.

Non-streaming mode

For non-streaming chat completion, send a request to the POST /v3/mira/chat endpoint:

curl -X POST \
--url "https://api.meltwater.com/v3/mira/chat" \
--header "Accept: application/json" \
--header "apikey: **********" \
--data '{
"user_prompt": "What is going on in the news with fast fashion in the last 7 days?",
"stream": false
}'

If the request is successful you will see a response similar to below, with the response content itself in Markdown:

{
"messages": [
"1. **Shein Faces Backlash Amid Pop-Up Store Launch in Dijon**\n - Summary: Shein's pop-up store in Dijon attracted hundreds of customers but also faced protests..."
],
"thread_id": "684afd4a43dc9fef57f754cb"
}

Currently only a single message will be returned in the messages field.

The thread_id field returned allows you to continue the conversation. So for example, you could ask a follow-up question for more details:

curl -X POST \
--url "https://api.meltwater.com/v3/mira/chat" \
--header "Accept: application/json" \
--header "apikey: **********" \
--data '{
"user_prompt": "Which story had the highest reach?",
"stream": false,
"thread_id": "684afd4a43dc9fef57f754cb"
}'

Note that in non-streaming mode, the API will wait for up to 300 seconds for the chat response to be completed by the system. If the response exceeds 300 seconds the API will return a 504 status code and an error message.

Streaming mode

For chat completion in streaming mode set the stream field to true:

curl -X POST \
--url "https://api.meltwater.com/v3/mira/chat" \
--header "Accept: application/json" \
--header "apikey: **********" \
--data '{
"user_prompt": "What is going on in the news with fast fashion in the last 7 days?",
"stream": true
}'

The API will respond by streaming server-side events, similar to the following:

data: {"id":"chatcmpl-43d3c1b9-08a4-4613-b42e-544560628814","object":"chat.completion.chunk","created":1749745452,"choices":[{"index":0,"delta":{"role":"assistant","content":"Analy"}}]}

data: {"id":"chatcmpl-43d3c1b9-08a4-4613-b42e-544560628814","object":"chat.completion.chunk","created":1749745452,"choices":[{"index":0,"delta":{"content":"zing"}}]}

....

data: [DONE]

The [DONE] event can be used to detect when the response stream has been completed.

Note that for streaming mode the Thread ID is returned as a response header called Thread-Id.

Rate limits

Calls are limited to 100 requests per minute.