# Supported Model Providers in AgentScope: Configuration Guide and Code Examples

> Explore supported model providers in AgentScope including OpenAI, Anthropic, and Gemini. This guide offers configuration details and code examples for seamless integration.

- Repository: [AgentScope-AI/agentscope](https://github.com/agentscope-ai/agentscope)
- Tags: configuration-guide
- Published: 2026-03-09

---

**AgentScope supports nine major LLM providers—OpenAI, Azure OpenAI, Anthropic, Google Gemini, Alibaba DashScope, Ollama, DeepSeek, Moonshot, and AWS Bedrock—through a unified `ChatModelBase` interface that standardizes authentication and request handling.**

AgentScope is a multi-agent framework that abstracts diverse language model APIs behind a consistent Python interface. When you instantiate a model, the framework uses provider-name mapping logic defined in the tracing utilities to identify the vendor and generate appropriate telemetry attributes. Understanding the supported model providers in AgentScope and their configuration patterns is essential for building robust agent workflows.

## Overview of Supported Model Providers

AgentScope currently integrates with the following providers, each mapped to a specific implementation class and identified by a unique provider key:

- **OpenAI** (`openai` or `trinity`): Implemented in `OpenAIChatModel` in [`src/agentscope/model/_openai_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/model/_openai_model.py). Supports models like `gpt-4o` and `gpt-3.5-turbo`.
- **Azure OpenAI** (`azure_ai_openai`): Uses `OpenAIChatModel` with a custom `base_url` pointing to your Azure endpoint.
- **Alibaba DashScope** (`dashscope`): Implemented in `DashScopeChatModel` in [`src/agentscope/model/_dashscope_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/model/_dashscope_model.py). Supports `qwen-max` and DeepSeek models.
- **DeepSeek** (`deepseek`): Uses the DashScope implementation via `DashScopeChatModel` with DeepSeek-specific model names.
- **Anthropic** (`anthropic`): Implemented in `AnthropicChatModel` in [`src/agentscope/model/_anthropic_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/model/_anthropic_model.py). Supports Claude models like `claude-3-opus-20240229`.
- **Google Gemini** (`gemini`): Implemented in `GeminiChatModel` in [`src/agentscope/model/_gemini_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/model/_gemini_model.py).
- **Ollama** (`ollama`): Implemented in `OllamaChatModel` in [`src/agentscope/model/_ollama_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/model/_ollama_model.py) for local deployment.
- **Moonshot AI** (`moonshot`): Uses `OpenAIChatModel` with an OpenAI-compatible API endpoint.
- **AWS Bedrock** (`aws_bedrock`): Uses `OpenAIChatModel` with Bedrock's OpenAI-compatible endpoint.

The provider enumeration is defined in [`src/agentscope/tracing/_attributes.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_attributes.py) within the `ProviderNameValues` enum, while the resolution logic resides in [`src/agentscope/tracing/_extractor.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_extractor.py).

## How AgentScope Detects Providers

When you create a model instance, AgentScope determines the provider through a cascading inspection process defined in [`src/agentscope/tracing/_extractor.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_extractor.py) (lines 31-48):

1. **Class Name Inspection**: The extractor first examines the concrete model class (e.g., `OpenAIChatModel`, `DashScopeChatModel`).
2. **Base URL Fragment Analysis**: For generic implementations like `OpenAIChatModel`, the framework inspects the `base_url` parameter for known fragments (`api.openai.com`, `openai.azure.com`, `dashscope`, etc.) to resolve ambiguous cases.
3. **Telemetry Attribution**: The resolved provider name is stored in the `GEN_AI_PROVIDER_NAME` span attribute for OpenTelemetry tracing, as defined in [`src/agentscope/tracing/_attributes.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_attributes.py) (lines 153-182).

This detection mechanism enables AgentScope to distinguish between OpenAI and Azure OpenAI even when both use the same underlying class.

## Common Configuration Parameters

All model classes inherit from `ChatModelBase` and accept the following standardized arguments:

- **`model_name`**: The provider-specific model identifier (e.g., `gpt-4o`, `qwen-max`).
- **`api_key`**: Authentication token. If omitted, the class automatically reads from standard environment variables (`OPENAI_API_KEY`, `DASHSCOPE_API_KEY`, `ANTHROPIC_API_KEY`, etc.) as implemented in each model's `__init__` method.
- **`base_url`** (optional): Override the default API endpoint. Required for Azure OpenAI, custom OpenAI-compatible servers, and certain third-party providers.
- **`**kwargs`**: Provider-specific parameters (e.g., `temperature`, `max_tokens`) passed directly to the underlying SDK client.

In [`src/agentscope/model/_openai_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/model/_openai_model.py) (line 91), the `OpenAIChatModel` class explicitly implements the fallback logic: `api_key=os.environ.get("OPENAI_API_KEY")`.

## Provider Configuration Examples

### OpenAI

Configure OpenAI models using the `OpenAIChatModel` class. The framework automatically reads `OPENAI_API_KEY` from your environment if not provided explicitly.

```python
from agentscope.model import OpenAIChatModel

model = OpenAIChatModel(
    model_name="gpt-4o-mini",
    api_key="sk-your-openai-key",  # Optional: falls back to OPENAI_API_KEY env var

    temperature=0.7,
)
response = model.chat(messages=[{"role": "user", "content": "Hello!"}])
print(response.content)

```

### Azure OpenAI

Azure deployments require the `base_url` parameter pointing to your Azure OpenAI endpoint, along with the `api_version` parameter.

```python
from agentscope.model import OpenAIChatModel

model = OpenAIChatModel(
    model_name="gpt-4o",
    api_key="your-azure-key",
    base_url="https://my-resource.openai.azure.com/",
    api_version="2024-02-01",
)

```

### Alibaba DashScope

DashScope provides access to Qwen models. Configure using `DashScopeChatModel` with your `DASHSCOPE_API_KEY`.

```python
from agentscope.model import DashScopeChatModel

model = DashScopeChatModel(
    model_name="qwen-max",
    api_key="your-dashscope-key",  # Optional: falls back to DASHSCOPE_API_KEY

    temperature=0.5,
)

```

### DeepSeek via DashScope

DeepSeek models are accessed through the DashScope provider using the same `DashScopeChatModel` class with DeepSeek-specific model identifiers.

```python
from agentscope.model import DashScopeChatModel

model = DashScopeChatModel(
    model_name="deepseek-chat",
    api_key="your-dashscope-key",
)

```

### Anthropic Claude

Configure Anthropic models using `AnthropicChatModel`, which reads `ANTHROPIC_API_KEY` from the environment by default.

```python
from agentscope.model import AnthropicChatModel

model = AnthropicChatModel(
    model_name="claude-3-opus-20240229",
    api_key="your-anthropic-key",  # Optional: falls back to ANTHROPIC_API_KEY

    max_tokens=1024,
)

```

### Google Gemini

Gemini models require the `GeminiChatModel` class and a `GEMINI_API_KEY` environment variable or explicit parameter.

```python
from agentscope.model import GeminiChatModel

model = GeminiChatModel(
    model_name="gemini-1.5-pro",
    api_key="your-gemini-key",  # Optional: falls back to GEMINI_API_KEY

)

```

### Ollama Local Deployment

Ollama enables local inference without API keys. The `OllamaChatModel` connects to your local Ollama server.

```python
from agentscope.model import OllamaChatModel

model = OllamaChatModel(
    model_name="llama3",
    temperature=0.8,
    # base_url defaults to http://localhost:11434 if not specified

)

```

### Moonshot AI

Moonshot uses an OpenAI-compatible API, allowing configuration through `OpenAIChatModel` with a custom `base_url`.

```python
from agentscope.model import OpenAIChatModel

model = OpenAIChatModel(
    model_name="moonshot-v1-8k",
    api_key="your-moonshot-key",
    base_url="https://api.moonshot.cn/v1",
)

```

## Summary

- **AgentScope unifies nine providers**—OpenAI, Azure OpenAI, Anthropic, Gemini, DashScope, DeepSeek, Ollama, Moonshot, and AWS Bedrock—behind the `ChatModelBase` interface.
- **Provider detection** occurs via class inspection in [`src/agentscope/tracing/_extractor.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_extractor.py) and URL fragment analysis, storing results in `GEN_AI_PROVIDER_NAME` attributes defined in [`src/agentscope/tracing/_attributes.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_attributes.py).
- **Configuration requires** `model_name` and optionally `api_key` (with automatic environment variable fallback) and `base_url` for custom endpoints.
- **Implementation classes** like `OpenAIChatModel`, `DashScopeChatModel`, and `AnthropicChatModel` handle provider-specific SDK initialization while exposing a consistent `.chat()` interface.

## Frequently Asked Questions

### How do I switch between different providers in AgentScope?

Import the specific model class for your provider (e.g., `AnthropicChatModel` for Anthropic, `DashScopeChatModel` for Alibaba) and instantiate it with the appropriate `model_name` and credentials. All classes share the same `.chat()` method signature, so you can swap implementations without changing your agent conversation logic.

### Can I use local models without API keys in AgentScope?

Yes. The `OllamaChatModel` class supports local inference via Ollama without requiring API keys. Simply specify the `model_name` corresponding to your locally downloaded model (e.g., `llama3`), and ensure your Ollama server is running on the default port or specify a custom `base_url`.

### How does AgentScope determine the provider name for tracing?

The framework inspects the concrete model class name and, for OpenAI-compatible implementations, analyzes the `base_url` for provider-specific fragments (like `openai.azure.com` for Azure or `api.moonshot.cn` for Moonshot). This logic in [`src/agentscope/tracing/_extractor.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_extractor.py) maps instances to provider keys defined in [`src/agentscope/tracing/_attributes.py`](https://github.com/agentscope-ai/agentscope/blob/main/src/agentscope/tracing/_attributes.py) for OpenTelemetry telemetry.

### What environment variables does AgentScope check for authentication?

Each model class checks for a provider-specific variable: `OPENAI_API_KEY` for OpenAI/Azure, `DASHSCOPE_API_KEY` for DashScope/DeepSeek, `ANTHROPIC_API_KEY` for Anthropic, and `GEMINI_API_KEY` for Gemini. If the `api_key` parameter is omitted during instantiation, the constructor automatically falls back to these environment variables as implemented in the respective [`_xxx_model.py`](https://github.com/agentscope-ai/agentscope/blob/main/_xxx_model.py) files.