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 the Mira API Beta program

Authentication

You need to provide your API token when you call any Meltwater API endpoint.

You provide the API token as a header called apikey, for example:

curl -X GET \
  --url "https://api.meltwater.com/v3/searches" \
  --header "Accept: application/json" \
  --header "apikey: **********"

For full details take a look at the Authentication page.

Chat completion endpoint

The API supports chat completion in both streaming and non-streaming mode through the POST /v3/assistants/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

Non-streaming mode

For non-streaming chat completion, you send a request to the POST /v3/assistants/chat endpoint.

curl -X POST \
  --url "https://api.meltwater.com/v3/assistants/chat" \
  --header "Accept: application/json" \
  --header "apikey: **********" \
  --data '{
	"user_prompt": "What were the top stories for Adidas last week?",
	"stream": false
}'

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

Example response:

{
	"messages": [
		"1. **Adidas Collaborates on Supply Chain Transparency**\n   - Summary: Adidas, alongside brands like Hugo Boss and Primark, contributed to TrusTrace's new playbook on supply chain traceability, launched at the Global Fashion Summit. The initiative aims to streamline data collection for compliance with industry regulations and enhance supply chain transparency[^9][^10].\n\n2. **Adidas Faces Competition in Golfwear**\n   - Summary: Adidas and Nike are facing rising competition in the golfwear market as Lululemon expands its presence, signing PGA Tour pro Max Homa as an ambassador. This move highlights a shift in consumer preferences towards more versatile and stylish golf apparel[^19][^20].\n\n3. **Adidas and Aaliyah Edwards Support STEM Education**\n   - Summary: Adidas partnered with WNBA player Aaliyah Edwards to donate $10,000 to Simon Elementary School in Washington, D.C., supporting STEM education. This initiative reflects Adidas' commitment to community engagement and educational development[^11][^12].\n\n4. **Adidas Prepares for Signature Sneaker Launch**\n   - Summary: Adidas is reportedly developing a signature sneaker for WNBA star Aliyah Boston, marking a significant milestone in women's basketball. This move positions Adidas as a leader in promoting female athletes in the sneaker market[^21][^22].\n\n5. **Adidas Products Featured in Amazon Deals**\n   - Summary: Adidas products, including technical t-shirts and cycling shoes, were highlighted in Amazon's weekly deals, offering significant discounts. This promotion aligns with Adidas' strategy to reach a broader consumer base through online retail[^20][^23]."
	],
	"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/assistants/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 you simply set the streaming field to true in your request to the POST /v3/assistants/chat endpoint.

curl -X POST \
  --url "https://api.meltwater.com/v3/assistants/chat" \
  --header "Accept: application/json" \
  --header "apikey: **********" \
  --data '{
	"user_prompt": "What were the top stories for Adidas last week?",
	"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.

Endpoint specification