Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.3 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { HttpMethod, httpClient } from '@activepieces/pieces-common';
import { mistralAuth } from '../common/auth';
import { parseMistralError } from '../common/props';
import { mistralRequest } from '../common/request';
import { listModelsOutputSchema } from '../output-schemas';

export const listModels = createAction({
  audience: 'both',
	auth: mistralAuth,
	name: 'list_models',
	classification: 'SEARCH',
	displayName: 'List Models',
	description: 'Retrieves a list of available Mistral AI models.',
	aiMetadata: { description: 'Returns every model the connected Mistral key can access, chat, embedding and OCR ids alike, exactly as the models endpoint reports them. Use it to discover a valid model id before calling Ask Mistral or Run OCR, both of which require one; it is the only discovery action here and takes no inputs, so it cannot filter or search. Read-only and idempotent.', idempotent: true },
	outputSchema: listModelsOutputSchema,
	props: {},
	async run({ auth }) {
		const { baseUrl, headers } = mistralRequest.getConfig(auth);
		try {
			const response = await httpClient.sendRequest({
				method: HttpMethod.GET,
				url: `${baseUrl}/models`,
				headers,
			});

			return response.body;
		} catch (e: any) {
			throw new Error(parseMistralError({ error: e, baseUrl }));
		}
	},
});