Skip to main content

SDK integration

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.
Keep 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
To verify the download, run this command from the extracted package directory:
shasum -a 256 -c SHA256SUMS.txt

Configure the connection

Common options

ParameterTypeDescription
ApiKeystring?API key; falls back to DASHSCOPE_API_KEY.
WorkspaceIdstring?Workspace ID, sent in X-DashScope-WorkSpace.
UrlstringFull 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
Qwen-Audio / Fun-ASR-Realtime / CosyVoice / Qwen-Audio-TTS-Nextwss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference
Real-time multimodal / Real-time voice conversation / Real-time audio and video translationwss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtime
Qwen-Audio-ASR-Filetrans / Fun-ASRhttps://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api/v1/services/audio/asr/transcription
Qwen-Audio-ASR / Fun-ASR-Flashhttps://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Paraformer · Real-time speech recognitionwss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference
Paraformer · Non-real-time speech recognitionhttps://WorkspaceId.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/asr/transcription

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.ap-southeast-1.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
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
  • Real-time voice conversation
  • Non-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.

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
240001ConfigInvalidInvalid configuration.
240002IllegalParamInvalid or missing parameter.
240014StateInvalidOperation not allowed in the current state.
240051UpdateAudioErrorAudio send failure.
240062NetworkErrorNetwork or connection error.
240069SocketClosedConnection closed; check the message for a local cancellation or remote closure.
240070AuthFailedAuthentication failure.
240072HttpSendFailedFailed to send the HTTP request.
240073HttpReceiveFailedThe HTTP response body is empty.
240074HttpResponseInvalidInvalid JSON or a required response field is missing.
240075HttpServerErrorServer returned an error; inspect the server error fields.
240080ServerErrorThe service reported task-failed. Check ServerErrorCode.
240091ConnectionTimeoutConnection timeout.
240092StartTimeoutTimeout waiting for the task-start event.
240093StopTimeoutTimeout waiting for task completion.