Skip to content

DashScope

The DashScope provider uses provider key dashscope and the HPD-Agent.Providers.DashScope package. ModelName is a DashScope or Qwen chat model id for chat, or a DashScope embedding model id for embeddings.

The provider package is currently net10.0 only. It uses the Cnblogs DashScope Microsoft.Extensions.AI adapter, which targets net8.0 and depends on Microsoft.Extensions.AI.Abstractions 10.7.0.

Set an API key with the primary environment variable:

bash
export DASHSCOPE_API_KEY="..."

The provider also registers QWEN_API_KEY and DASHSCOPE_KEY as API key aliases.

Use fluent chat setup first:

csharp
using HPD.Agent;
using HPD.Agent.Providers.DashScope;

var agent = await new AgentBuilder()
    .WithDashScope(model: "qwen-plus")
    .BuildAsync();

var result = await agent.RunAsync("Write one sentence about DashScope setup.");
Console.WriteLine(result.Text);

Provider construction options stay focused on the DashScope connection and endpoint selection. Put model behavior on chat defaults or per-run chat config:

csharp
using HPD.Agent;
using HPD.Agent.Providers.DashScope;

var agent = await new AgentBuilder()
    .WithDashScope(
        model: "qwen-plus",
        configure: dashScope =>
        {
            dashScope.WorkspaceId = "your-workspace-id";
            dashScope.TimeoutSeconds = 120;
        })
    .WithChatDefaults(chat =>
    {
        chat.Temperature = 0.2;
        chat.MaxOutputTokens = 4096;
        chat.Reasoning = new ReasoningOptions
        {
            Effort = ReasoningEffort.High
        };
    })
    .WithDashScopeChatRequestOptions(dashScope =>
    {
        dashScope.EnableSearch = true;
        dashScope.ThinkingBudget = 1024;
        dashScope.SearchOptions = new DashScopeSearchRequestOptions
        {
            EnableCitation = true,
            SearchStrategy = DashScopeSearchStrategy.Turbo
        };
    })
    .BuildAsync();

The equivalent Clients.Chat shape is:

json
{
  "Clients": {
    "Chat": {
      "ProviderKey": "dashscope",
      "ModelName": "qwen-plus",
      "ChatDefaults": {
        "Temperature": 0.2,
        "MaxOutputTokens": 4096,
        "Reasoning": {
          "Effort": "High"
        },
        "AdditionalProperties": {
          "enable_search": true,
          "thinking_budget": 1024,
          "search_options": {
            "enableCitation": true,
            "searchStrategy": "turbo"
          }
        }
      },
      "ProviderOptions": {
        "workspaceId": "your-workspace-id",
        "timeoutSeconds": 120
      }
    }
  }
}

Embeddings

DashScope also registers the embeddings provider family under the same dashscope key:

csharp
using HPD.Agent;
using HPD.Agent.Providers.DashScope;

var agent = await new AgentBuilder()
    .WithDashScopeEmbeddings(model: "text-embedding-v4")
    .BuildAsync();

The equivalent family config is:

json
{
  "Clients": {
    "Embeddings": {
      "ProviderKey": "dashscope",
      "ModelName": "text-embedding-v4"
    }
  }
}

Runtime Chat Options

Use ChatRunConfig for shared model-call behavior such as temperature, top-p, top-k, max output tokens, stop sequences, tools, tool mode, seed, and generic reasoning options. Put agent-level defaults in ClientProviderConfig.ChatDefaults or .WithChatDefaults(...); use AgentRunConfig.Chat for per-run or per-session overrides.

Use DashScopeChatRequestOptions for DashScope-only request properties:

OptionDashScope keyMeaning
UseVluseVlForces the request to use DashScope multimodal generation endpoints.
EnableSearchenable_searchEnables DashScope web search for the request.
EnableTextImageMixedenable_text_image_mixedAllows image tags to appear in search-augmented text output.
SearchOptionssearch_optionsWeb-search controls. EnableSearch should also be enabled.
ThinkingBudgetthinking_budgetExact maximum thinking-content length for supported models. Use generic Reasoning for normal reasoning control.
PreserveThinkingpreserve_thinkingMakes previous reasoning content in chat history visible to the model.
EnableCodeInterpreterenable_code_interpreterEnables DashScope's internal code interpreter. This cannot be combined with normal tools.
LogprobslogprobsRequests output token log probabilities.
TopLogprobstop_logprobsNumber of likely token alternatives to return with log probabilities.
NnNumber of choices the model should generate.
LogitBiaslogit_biasToken id bias map. Values near -100 ban a token; values near 100 force selection.
TranslationOptionstranslation_optionsTranslation controls for Qwen-MT models.
CacheControlcache_controlCache-control options for supported DashScope models such as qwen-coder.
VlHighResolutionImagesvl_high_resolution_imagesAllows higher-resolution image inputs for multimodal models.
NegativePromptnegative_promptNegative prompt for supported multimodal or image-generation requests.

DashScopeSearchRequestOptions supports:

OptionMeaning
EnableSourceIncludes search source information in the response.
EnableCitationIncludes citations in generated output.
CitationFormatCitation format. DashScope defaults to a numbered bracket format.
ForcedSearchForces the model to use web search.
SearchStrategySearch strategy, such as DashScopeSearchStrategy.Turbo or DashScopeSearchStrategy.Max.
EnableSearchExtensionEnables enhanced search for supported areas.
PrependSearchResultReturns search results first when incremental output is enabled.
FreshnessLimits search content to a recent window in days, such as 7, 30, 180, or 365.
AssignedSiteListRestricts search to the specified sites.

DashScopeTranslationRequestOptions supports SourceLang, TargetLang, and Domains. Use SourceLang = "auto" to enable automatic detection.

DashScopeCacheControlRequestOptions supports Type; DashScope defaults to DashScopeCacheControlType.Ephemeral.

DashScope Provider Options

DashScopeProviderConfig exposes DashScope connection, multimodal, and embedding settings:

csharp
var agent = await new AgentBuilder()
    .WithDashScope(
        model: "qwen-plus",
        configure: options =>
        {
            options.WorkspaceId = "your-workspace-id";
            options.DefaultUseVl = true;
        })
    .BuildAsync();

Set Endpoint on ClientProviderConfig or baseAddress in provider options for a custom HTTP base URL. websocketBaseAddress, workspaceId, socketPoolSize, and timeoutSeconds are available when the underlying DashScope SDK needs them.

For multimodal models, the adapter auto-detects common qwen-vl, qwen3-vl, qwen3-omni, and gui-plus model ids. Set DefaultUseVl = true when you need to force the multimodal endpoint by default; set DashScopeChatRequestOptions.UseVl for a single request.

OptionPurpose
BaseAddressDashScope HTTP API base address. Endpoint on ClientProviderConfig can also set a custom HTTP base URL.
WebsocketBaseAddressDashScope websocket API base address.
WorkspaceIdWorkspace id sent with DashScope requests that require workspace scoping.
SocketPoolSizeInternal websocket pool size used by the DashScope SDK.
TimeoutSecondsRequest timeout in seconds for the underlying DashScope HTTP client.
DefaultUseVlForces multimodal generation endpoints by default. Leave unset to let the adapter infer from common VL, omni, and GUI model ids.
EmbeddingModelIdDefault embedding model id for the embeddings provider family.
EmbeddingDimensionsOptional embedding dimensions.

Caveats

DashScope chat and embeddings are available only when the HPD-Agent.Providers.DashScope package is referenced by a net10.0 application.

The provider uses the Cnblogs adapter rather than a custom protocol implementation. Provider metadata reports streaming, function calling, reasoning, and vision because the adapter maps MEAI streaming, tools, reasoning content, and multimodal content to DashScope APIs.

Generic HPD reasoning maps to DashScope enable_thinking on the currently referenced Cnblogs.DashScope.AI package. More granular DashScope reasoning fields such as reasoning effort are not exposed by that package version.

Validation checks API key, model, endpoint/base URL, websocket URL, workspace-related numeric options, multimodal options, and embedding options. Runtime chat options are applied through ChatDefaults and AgentRunConfig.Chat. Missing credentials fail at BuildAsync() before a live provider call.

Built for production .NET agent applications.