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_KEYenvironment variable.
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.
- Local NuGet source (recommended)
- Reference the DLL directly
Use the extracted
packages/ directory as a local NuGet source.The examples use .NET 8. For .NET 10, replace
net8.0 with net10.0 in commands and paths.Configure the connection
Common options
| Parameter | Type | Description |
|---|---|---|
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.
| Capability | URL |
|---|---|
| Qwen-Audio / Fun-ASR-Realtime / CosyVoice / Qwen-Audio-TTS-Next | wss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference |
| Real-time multimodal / Real-time voice conversation / Real-time audio and video translation | wss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtime |
| Qwen-Audio-ASR-Filetrans / Fun-ASR | https://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api/v1/services/audio/asr/transcription |
| Qwen-Audio-ASR / Fun-ASR-Flash | https://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation |
| Paraformer · Real-time speech recognition | wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference |
| Paraformer · Non-real-time speech recognition | https://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.
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.
| Type | Supported models | C# client |
|---|---|---|
| Real-time multimodal |
| QwenRealtimeConversation |
| Real-time speech recognition |
| FunAsrSpeechTranscriber |
| Real-time speech synthesis |
| CosyVoiceSpeechSynthesizer |
| Audio Generation |
| CosyVoiceSpeechSynthesizer |
| Real-time voice conversation |
| QwenRealtimeConversation |
| Real-time audio and video translation |
| QwenLiveTranslator |
| Non-real-time speech recognition (asynchronous) |
| FunAsrFileTranscriber |
| Non-real-time speech recognition (single request) |
| FunAsrFlashFileTranscriber |
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 code | DashScopeErrorCode | Description |
|---|---|---|
| 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. |