Large Language Models (LLMs) with MATLAB lets you connect to large language model APIs using MATLAB®.
Note
For a simplified approach to building LLM and agentic applications in MATLAB, see the research preview of MATLAB AI Agent SDK.
Large Language Models (LLMs) with MATLAB will no longer get new features.
You can connect to:
- OpenAI® Chat Completions API — For example, connect to ChatGPT™.
- OpenAI-compatible APIs — Connect to APIs that are compatible with the OpenAI Chat Completions API.
- OpenAI Images API — Connect to image generation models from OpenAI.
- Azure® OpenAI Service — Connect to OpenAI models from Azure.
- Ollama™ — Connect to models locally or nonlocally.
Using this add-on, you can:
- Generate responses to natural language prompts.
- Manage chat history.
- Generate JSON-formatted and structured output.
- Use tool calling.
- Call external tools provided by MCP servers (requires the MATLAB MCP HTTP Client add-on).
- Generate, edit, and describe images.
For more information about the features in this add-on, see the documentation in the doc directory.
Using this add-on requires MATLAB R2024a or newer.
You can use the add-on in MATLAB Online™ by clicking this link:
In MATLAB Online, you can connect to OpenAI and Azure. To connect to Ollama, use an installed version of MATLAB and install the add-on using the Add-On Explorer or by cloning the GitHub™ repository.
The recommended way of using the add-on on an installed version of MATLAB is to use the Add-On Explorer.
- In MATLAB, go to the Home tab, and in the Environment section, click the Add-Ons icon.
- In the Add-On Explorer, search for "Large Language Models (LLMs) with MATLAB".
- Select Install.
For more information about how to connect to the different APIs from MATLAB, including installation requirements, see:
- Process Generated Text in Real Time by Using ChatGPT in Streaming Mode
- Process Generated Text in Real Time by Using Ollama in Streaming Mode
- Summarize Large Documents Using ChatGPT and MATLAB (requires Text Analytics Toolbox™)
- Create Simple ChatBot (requires Text Analytics Toolbox)
- Create Simple Ollama ChatBot (requires Text Analytics Toolbox)
- Solve Simple Math Problem Using AI Agent
- Fit Polynomial to Data Using AI Agent (requires Curve Fitting Toolbox™)
- Analyze Table Data Using ChatGPT
- Visualize Table Data Using ChatGPT
- Build Optimization Problem Using ChatGPT (requires Optimization Toolbox™ and Global Optimization Toolbox™)
- Analyze Scientific Papers Using ChatGPT Function Calls
- Analyze Text Data Using Parallel Function Calls with ChatGPT
- Analyze Text Data Using Parallel Function Calls with Ollama
- Retrieval-Augmented Generation Using ChatGPT and MATLAB (requires Text Analytics Toolbox)
- Retrieval-Augmented Generation Using Ollama and MATLAB (requires Text Analytics Toolbox)
- Add OpenTelemetry Observability to AI Agent (OpenTelemetry-MATLAB)
| Function | Description |
|---|---|
| openAIChat | Connect to OpenAI Chat Completion API from MATLAB |
| azureChat | Connect to Azure OpenAI Services Chat Completion API from MATLAB |
| ollamaChat | Connect to Ollama Server from MATLAB |
| generate | Generate output from large language models |
| openAIFunction | Use Function Calls from MATLAB |
| addParameter | Add input argument to openAIFunction object |
| openAIImages | Connect to OpenAI Image Generation API from MATLAB |
| openAIImages.generate | Generate image using OpenAI image generation API |
| edit | Edit images using OpenAI image generation API |
| messageHistory | Manage and store messages in a conversation |
| addSystemMessage | Add system message to message history |
| addUserMessage | Add user message to message history |
| addUserMessageWithImages | Add user message with images to message history |
| addToolMessage | Add tool message to message history |
| addResponseMessage | Add response message to message history |
| removeMessage | Remove message from message history |
The license is available in the license.txt file in this GitHub repository.
Copyright 2023-2026 The MathWorks, Inc.