---
question: How do I add OpenAI or Ollama as a provider?
kind: task
via_web: na
via_cli: na
via_python: available
via_api: na
via_config: available
ref_python: ModelDescriptor
ref_config: modules:
next:
  - /capabilities/build/models/choose-the-default-model
  - /capabilities/build/agents/edit-prompt-and-model
---

# Add a provider

A provider is a marketplace module that registers models in the engine's model registry. The marketplace ships one per vendor under `naas_abi_marketplace.ai` (Anthropic, OpenAI, Gemini, Mistral, OpenRouter, Ollama, and others): enable it under `modules:` in `config.yaml` with its key. For a model the marketplace does not have, a module of your project can serve it from its own process, to the other modules.

## Web UI

Not applicable. Nexus does not enable modules: Settings › Models lists every marketplace provider's models, **Not configured** until you enable the module on the Config tab.

## CLI

Not applicable. There is no `abi new model` command: a provider is a module enabled in `config.yaml`, on the Config tab, and `abi config validate --modules` checks it.

## Python

### Write the handler

A module serves a chat model through a handler with an async `invoke(messages)`. It gets LangChain messages and returns text or an `AIMessage`:

```python title="src/my_llm/chat.py"
import os

from langchain_openai import ChatOpenAI


class MyChat:
    def __init__(self) -> None:
        self.llm = ChatOpenAI(
            model="my-chat-v1",
            base_url="https://models.example.com/v1",
            api_key=os.environ["MY_LLM_API_KEY"],
        )

    async def invoke(self, messages):
        return await self.llm.ainvoke(messages)
```

Inference runs in the module's process, so the provider's key and client live there: add the client library to the module's image. A handler that also takes `tools` (and `tool_options`) can return an `AIMessage` with tool calls; the caller's agent runs the tools.

### Declare and bind it

```python title="src/my_llm/__init__.py"
from naas_abi_sdk import BaseModule, ModelDescriptor

from my_llm.chat import MyChat


class ABIModule(BaseModule[MyLlmConfiguration]):
    models = (ModelDescriptor("my-chat", "My chat model"),)

    async def on_initialized(self) -> None:
        self.expose_model("my-chat", MyChat())
```

`expose_model` refuses a name without a chat `ModelDescriptor`, and a handler whose `invoke` is not async. Discovery publishes the model with the module once it is `READY`.

### Use it from another module

The caller names the module in its dependencies and asks it for the model:

```python title="src/research/__init__.py"
class ABIModule(BaseModule[ResearchConfiguration]):
    dependencies = ModuleDependencies(
        services=("model_registry", "document", "triple_store"),  # the scaffold's services
        modules=("my_project.my_llm",),
    )

    async def on_initialized(self) -> None:
        chat = await self.engine.modules["my_project.my_llm"].get_chat_model("my-chat")
        llm = chat.model  # a LangChain chat model
```

A module's model is not in the engine's model registry: Settings › Models does not list it, it cannot be a default model, and `registry.get_chat_model("my-chat")` does not find it. Each call is one request and one answer: streaming is refused. To add a vendor to the registry itself, use a marketplace provider module, as on the Config tab.

## REST API

Not applicable. There is no REST endpoint that registers a model provider: a provider is a module, and the default model is `services.model_registry` in `config.yaml`.

## Config

### Install the module's extra

The marketplace modules need their package extra. For Anthropic:

```bash
uv add "naas-abi-marketplace[ai-claude]"
```

OpenRouter needs none. See [Marketplace install](/capabilities/build/modules/marketplace/marketplace-install).

### Enable the module

Add it under `modules:` with its key, read from the secret service:

```yaml title="config.yaml"
modules:
  - module: naas_abi_marketplace.ai.anthropic
    enabled: true
    config:
      anthropic_api_key: "{{ secret.ANTHROPIC_API_KEY }}"
```

The key field is named after the vendor: `openai_api_key`, `gemini_api_key`, `mistral_api_key`, `openrouter_api_key`, and so on. Ollama needs no key: see [Run models locally](/capabilities/build/models/run-models-locally).

### Store the key

```bash title=".env"
ANTHROPIC_API_KEY=sk-ant-...
```

### Check and restart

```bash
abi config validate --modules
```

It imports every enabled module and validates its config. Restart the engine: Settings › Models then marks that module's models **Configured**, and agents can ask for them by canonical id.

## The default model

The engine checks `default_chat_model` and `default_embedding_model` after the modules load, and stops when one is not registered. Before you disable a provider, move the defaults, and any agent model pinned in a module's config, to models another enabled module provides. See [Choose the default model](/capabilities/build/models/choose-the-default-model).
