SDK overview

Updated at:

Install and configure the Model Studio C# SDK, select a client for your model family, and handle completion, timeouts, and errors.

Getting started

Prerequisites

  • Install the .NET 8 or .NET 10 SDK.
  • Get an API key, then set the DASHSCOPE_API_KEY environment variable.

WarningKeep long-lived API keys on your server. Do not embed them in distributed desktop, mobile, or browser applications. For guidance, see Protect your API key.

Install the SDK

Download and extract Bailian.DashScope-1.1.1.zip.

The NuGet package is Bailian.DashScope; the assembly is DashScope.dll and the root namespace is DashScope. The package has no native libraries or transitive NuGet dependencies.

Reference the DLL directly

For direct DLL references, select sdk/net8.0/DashScope.dll or sdk/net10.0/DashScope.dll for the target framework. Keep DashScope.xml next to the DLL for IDE documentation.

<ItemGroup>
  <Reference Include="DashScope">
    <HintPath>/path/to/Bailian.DashScope-1.1.1/sdk/net8.0/DashScope.dll</HintPath>
  </Reference>
</ItemGroup>

To verify the download, run this command from the extracted package directory:

shasum -a 256 -c SHA256SUMS.txt

Configure the connection

Common options

ParameterTypeDescription

ApiKey

string?

API key; falls back to DASHSCOPE_API_KEY.

WorkspaceId

string?

Workspace ID, sent in X-DashScope-WorkSpace.

Url

string

Full endpoint URL.

Configure the endpoint URL

Setting WorkspaceId adds the workspace request header; it does not change the endpoint. Set the complete workspace endpoint in Url.

For real-time multimodal interaction, voice conversation, and audio and video translation, the SDK adds the model name to the WebSocket URL as the model query parameter. For speech recognition, speech synthesis, and audio generation, it sends the model name in the request body.

CapabilityURL

Real-time speech recognition / Real-time speech synthesis / Audio Generation

wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference

Real-time multimodal / Real-time voice conversation / Real-time audio and video translation

wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/realtime

Qwen-Audio-ASR-Filetrans / Fun-ASR / Paraformer

https://WorkspaceId.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/asr/transcription

Qwen-Audio-ASR / Fun-ASR-Flash

https://WorkspaceId.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

Verify the installation and configuration

Run the following commands in the extracted demo/DashScope.Cli/ directory. The example converts audio to 16 kHz mono PCM and runs real-time speech recognition. Replace WorkspaceId with the workspace ID for your API key.

dotnet build -p:TargetFrameworks=net8.0
curl -fL "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav" -o input.wav
ffmpeg -i input.wav -f s16le -ac 1 -ar 16000 input.pcm
dotnet bin/Debug/net8.0/DashScope.Cli.dll asr --audio input.pcm --model qwen-audio-3.1-asr-flash-streaming --url "wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference"

Supported capabilities and models

Use this managed .NET SDK to send audio or text to Model Studio and receive results. It does not capture or encode audio, detect wake words, or perform local VAD or echo cancellation.

TypeSupported modelsC# client

Real-time multimodal

  • Qwen-Omni-Realtime: qwen3.8-omni-flash-realtime, qwen3.5-omni-plus-realtime, qwen3.5-omni-plus-realtime-2026-03-15, qwen3.5-omni-flash-realtime, qwen3.5-omni-flash-realtime-2026-03-15, qwen3-omni-flash-realtime-2025-09-15

QwenRealtimeConversation

Real-time speech recognition

  • Qwen-Audio-ASR-Streaming: qwen-audio-3.1-asr-flash-streaming, qwen-audio-3.0-asr-flash-streaming
  • Qwen-Audio-ASR-Message: qwen-audio-3.1-asr-flash-message
  • Fun-ASR-Realtime: fun-asr-realtime, fun-asr-flash-8k-realtime, fun-asr-realtime-2026-02-28, fun-asr-flash-8k-realtime-2026-01-28
  • Paraformer: paraformer-realtime-v2, paraformer-realtime-8k-v2

FunAsrSpeechTranscriber

Real-time speech synthesis

  • Qwen-Audio-TTS: qwen-audio-3.1-tts-flash, qwen-audio-3.1-tts-plus, qwen-audio-3.0-tts-flash, qwen-audio-3.0-tts-plus
  • CosyVoice: cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-flash, cosyvoice-v3-plus, cosyvoice-v2

CosyVoiceSpeechSynthesizer

Real-time speech synthesis

  • Sambert (Beijing only): sambert-beth-v1, sambert-betty-v1, sambert-brian-v1, sambert-cally-v1, sambert-camila-v1, sambert-cindy-v1, sambert-clara-v1, sambert-donna-v1, sambert-eva-v1, sambert-hanna-v1, sambert-indah-v1, sambert-perla-v1, sambert-waan-v1, sambert-zhichu-v1, sambert-zhida-v1, sambert-zhide-v1, sambert-zhifei-v1, sambert-zhigui-v1, sambert-zhihao-v1, sambert-zhijia-v1, sambert-zhijing-v1, sambert-zhilun-v1, sambert-zhimao-v1, sambert-zhimiao-emo-v1, sambert-zhiming-v1, sambert-zhimo-v1, sambert-zhina-v1, sambert-zhinan-v1, sambert-zhiqi-v1, sambert-zhiqian-v1, sambert-zhiru-v1, sambert-zhishu-v1, sambert-zhishuo-v1, sambert-zhistella-v1, sambert-zhiting-v1, sambert-zhiwei-v1, sambert-zhixiang-v1, sambert-zhixiao-v1, sambert-zhiya-v1, sambert-zhiye-v1, sambert-zhiying-v1, sambert-zhiyuan-v1, sambert-zhiyue-v1

SambertSpeechSynthesizer

Audio Generation

  • Qwen-Audio-TTS-Next: qwen-audio-3.1-tts-next

CosyVoiceSpeechSynthesizer

Real-time voice conversation

  • Qwen-Audio-Realtime: qwen-audio-3.1-realtime-plus, qwen-audio-3.1-realtime-flash, qwen-audio-3.0-realtime-plus, qwen-audio-3.0-realtime-flash

QwenRealtimeConversation

Real-time audio and video translation

  • Qwen-LiveTranslate-Realtime: qwen3.5-livetranslate-flash-realtime, qwen3.5-livetranslate-flash-realtime-2026-05-19, qwen3.8-livetranslate-flash-realtime

QwenLiveTranslator

Non-real-time speech recognition (asynchronous)

  • Qwen-Audio-ASR-Filetrans: qwen-audio-3.1-asr-flash-filetrans, qwen-audio-3.0-asr-flash-filetrans
  • Fun-ASR: fun-asr
  • Paraformer: paraformer-v2, paraformer-8k-v2

FunAsrFileTranscriber

Non-real-time speech recognition (single request)

  • Qwen-Audio-ASR: qwen-audio-3.1-asr-flash, qwen-audio-3.0-asr-flash
  • Fun-ASR-Flash: fun-asr-flash-2026-06-15

FunAsrFlashFileTranscriber

Run the following command in the built demo project directory to list the model IDs included in the demo.

dotnet bin/Debug/net8.0/DashScope.Cli.dll models --names-only

Usage notes

Model and voice compatibility

If several model families share a client class, set Model explicitly. Otherwise, the SDK uses the class default. The SDK’s ModelRouting methods match some model families by name. Use the supported models table on this page to find the client for a model.

When you change a synthesis model, choose a voice supported by that model. Qwen-Audio-TTS and CosyVoice share a client, not a voice list. To select a voice, see Qwen-Audio-TTS voice list and CosyVoice voice list.

Finish or cancel a call

Real-time speech recognition

For realtime recognition and duplex synthesis, await StopAsync() to receive the final results. Calling it again does not raise another completion event. CancelAsync() closes the connection without waiting; it can be called more than once.

If you cancel while StopAsync() is waiting, that pending call fails with 240069. Calling StopAsync() after cancellation fails with 240014. Disposing an unfinished task instead of stopping it reports 240069 through Failed.

Real-time voice conversation

For conversation or translation, finish the session with FinishAsync() after the last response; the client selects the model’s FinishMode.

Non-real-time speech recognition

For asynchronous file transcription, canceling a local wait does not cancel the remote job: use CancelTaskAsync(taskId) while the job is pending.

Sambert

Sambert takes the full text once per instance. Select the speaker with Model, not Voice. After StartAsync(text), await WaitFinishedAsync(); the server ends the task.

Error codes

When a call fails, awaiting its result can throw DashScopeException. For real-time speech recognition and speech synthesis, subscribe to Failed to receive connection errors.

Use ServerErrorCode and ServerErrorMessage to diagnose server errors. When contacting technical support, include the TaskId and RequestId returned by the call, if available.

Error codeDashScopeErrorCodeDescription

240001

ConfigInvalid

Invalid configuration.

240002

IllegalParam

Invalid or missing parameter.

240014

StateInvalid

Operation not allowed in the current state.

240051

UpdateAudioError

Audio send failure.

240062

NetworkError

Network or connection error.

240069

SocketClosed

Connection closed; check the message for a local cancellation or remote closure.

240070

AuthFailed

Authentication failure.

240072

HttpSendFailed

Failed to send the HTTP request.

240073

HttpReceiveFailed

The HTTP response body is empty.

240074

HttpResponseInvalid

Invalid JSON or a required response field is missing.

240075

HttpServerError

Server returned an error; inspect the server error fields.

240080

ServerError

The service reported task-failed. Check ServerErrorCode.

240091

ConnectionTimeout

Connection timeout.

240092

StartTimeout

Timeout waiting for the task-start event.

240093

StopTimeout

Timeout waiting for task completion.