The Bulk Spell Run endpoint is very similar to the standard Run Spell endpoint with some key differences. Mainly, there is no wait mode, as you will always receive bulkRunId as a return value.

To call a spell, you’ll need to enter the spell ID (found in the URL or on the spell page’s API tab) and the JSON representation of the inputs (found in the spell page’s API tab).

Bulk Mode

To start the a bulk spell run:

const response = await fetch('https://api-v2.respell.ai/spells/bulkStart', {
  method: 'POST',
  headers: {
    authorization: 'Bearer {{ YOUR API KEY }}',
    accept: 'application/json',
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    spellId: '{{ YOUR SPELL ID }}',
    inputs: [{
        "search_topic": "{{ YOUR CUSTOM INPUT }}"
      },{
        "search_topic": "{{ YOUR SECOND CUSTOM INPUT }}"
      }]
  }),
})

The bulk run ID will be returned as JSON in the response body:

{
  "runId": "{{ BULK RUN ID }}"
}

Cancel Bulk Run

To cancel the bulk run:

const response = await fetch('https://api-v2.respell.ai/spells/cancelBulk', {
  method: 'POST',
  headers: {
    authorization: 'Bearer {{ YOUR API KEY }}',
    accept: 'application/json',
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    groupId: '{{ YOUR BULK RUN ID }}',
  }),
})

This will stop all runs immediately.

Get Bulk Runs

To get the results of a bulk run:

const response = await fetch('https://api-v2.respell.ai/spells/getBulkRuns', {
  method: 'POST',
  headers: {
    authorization: 'Bearer {{ YOUR API KEY }}',
    accept: 'application/json',
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    groupId: '{{ YOUR BULK RUN ID }}',
  }),
})

The data returned will look like:

{
	"runs": [
		{
			"state": "success",
			"outputs": {
				...
			}
		},
		....
	]
}