AutoSDK.CLI
0.30.1-dev.105
See the version list below for details.
dotnet tool install --global AutoSDK.CLI --version 0.30.1-dev.105
dotnet new tool-manifest
dotnet tool install --local AutoSDK.CLI --version 0.30.1-dev.105
#tool dotnet:?package=AutoSDK.CLI&version=0.30.1-dev.105&prerelease
nuke :add-package AutoSDK.CLI --version 0.30.1-dev.105
AutoSDK
The goal of this project is to automate and minimize the effort of maintaining high-quality .NET SDKs generated based on OpenAPI and AsyncAPI specifications, mainly to strengthen the AI ecosystem within .NET. The code generated by this library is also actively used in dozens of our various SDKs of varying complexity levels and in the LangChain.NET project, which ensures that it is tested in various scenarios and is ready for them.
Inspired by NSwag ❤️.
🔥Features🔥
- Detects your TargetFramework and generates optimal code for it (including net6.0/net7.0/net8.0 improvements)
- Supports .Net Framework/.Net Standard
- Supports OpenAPI 3.1 specs via internal conversion to OpenAPI 3.0 (includes support for nullability, examples, const)
- Does not contain dependencies for modern versions of dotnet.
- Only System.Text.Json dependency for .Net Framework/.Net Standard
- Any generated methods provide the ability to pass a CancellationToken
- Allows partial generation (models only) or end points filtering
- Available under MIT license for general users and most organizations
- Uses https://github.com/microsoft/OpenAPI.NET for parsing OpenAPI specification
- Supports nullable enable/trimming/native AOT compilation/CLS compliance
- Tested on GitHub 220k lines OpenAPI specification
- Supports OneOf/AnyOf/AllOf/Not schemas
- Supports Enums for System.Text.Json
- Supports AsyncAPI specs for WebSocket client generation (send/receive methods, cross-namespace schema referencing)
- Supports SSE (Server-Sent Events) through the
application/x-ndjsoncontent type - Uses Incremental Source Generators for efficient generation and caching.
- Efficient O(n) implementation, fully suitable for large/super large OpenAPI specifications
- Used in 10+ real SDKs and adapted to solve various problems
🚀Quick start🚀
CLI (Recommended)
You can use the CLI to generate the code.
dotnet tool install --global autosdk.cli --prerelease
rm -rf Generated
autosdk generate openapi.yaml \
--namespace Namespace \
--clientClassName YourApi \
--targetFramework net8.0 \
--output Generated
It will generate the code in the "Generated" subdirectory.
It also will include polyfills for .Net Framework/.Net Standard TargetFrameworks.
Source generator
- Install the package
dotnet add package AutoSDK.SourceGenerators
- Add the following optional settings to your csproj file to customize generation. You can check all settings here:
<ItemGroup Label="AutoSDK">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)../../../docs/openapi.yaml" AutoSDK_OpenApiSpecification="true" />
</ItemGroup>
<PropertyGroup Label="AutoSDK">
<AutoSDK_Namespace>Ollama</AutoSDK_Namespace>
<AutoSDK_ClassName>OllamaApi</AutoSDK_ClassName>
<AutoSDK_GenerateSdk>false</AutoSDK_GenerateSdk>
<AutoSDK_GenerateModels>true</AutoSDK_GenerateModels>
<AutoSDK_GenerateMethods>true</AutoSDK_GenerateMethods>
<AutoSDK_GenerateConstructors>true</AutoSDK_GenerateConstructors>
<AutoSDK_IncludeOperationIds>getPet;deletePet</AutoSDK_IncludeOperationIds>
<AutoSDK_ExcludeOperationIds>getPet;deletePet</AutoSDK_ExcludeOperationIds>
<AutoSDK_IncludeModels>Pet;Model</AutoSDK_IncludeModels>
<AutoSDK_ExcludeModels>Pet;Model</AutoSDK_ExcludeModels>
</PropertyGroup>
- It's all! Now you can build your project and use the generated code. You also can use IDE to see the generated code in any moment, this is a example for Rider:
Trimming support
CLI
CLI generates Trimming/NativeAOT compatible code by default.
Source generator
Since there are two source generators involved, we will have to create a second project so that the generator for the JsonSerializerContext will “see” our models
- Create new project for your models. And disable methods/constructors generation:
<PropertyGroup Label="AutoSDK">
<AutoSDK_GenerateSdk>false</AutoSDK_GenerateSdk>
<AutoSDK_GenerateModels>true</AutoSDK_GenerateModels>
<AutoSDK_GenerateJsonSerializerContextTypes>true</AutoSDK_GenerateJsonSerializerContextTypes>
</PropertyGroup>
- Reference this project in your main project.
- Add
SourceGenerationContext.csfile to your main project with the following content:
using System.Text.Json.Serialization;
namespace Namespace;
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(AutoSDKTrimmableSupport))]
internal sealed partial class SourceGenerationContext : JsonSerializerContext;
- Add the following settings to your main csproj file:
<PropertyGroup Label="AutoSDK">
<AutoSDK_GenerateSdk>false</AutoSDK_GenerateSdk>
<AutoSDK_GenerateMethods>true</AutoSDK_GenerateMethods>
<AutoSDK_GenerateConstructors>true</AutoSDK_GenerateConstructors>
<AutoSDK_JsonSerializerContext>Namespace.SourceGenerationContext</AutoSDK_JsonSerializerContext>
</PropertyGroup>
- Add these settings to your new and main csproj file to enable trimming(or use Directory.Build.props file):
<PropertyGroup Label="Trimmable" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsAotCompatible>true</IsAotCompatible>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
- It's all! Now you can build your project and use the generated code with full trimming/nativeAOT support.
Known Errors
Generator error: "Could not write to output file 'Path/to/file'. Could not find part of the path"
This error happens if the generated file path is too long. This happens if you didn't activated long path support on windows. To enable it follow the offical docs: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#registry-setting-to-enable-long-paths
AsyncAPI / WebSocket Support
AutoSDK can generate typed WebSocket clients from AsyncAPI 3.0 specifications, producing send/receive methods for each channel operation.
Basic Usage
autosdk generate asyncapi.yaml \
--namespace MyApi.Realtime \
--websocket-class-name MyRealtimeClient \
--output Generated
This generates:
- A WebSocket client class with connect/disconnect lifecycle
- Typed
Send*methods for publish operations - Typed
Receive*methods (via event callbacks) for subscribe operations - All associated models, enums, and JSON converters
Cross-Namespace Schema Referencing
When an API has both REST (OpenAPI) and WebSocket (AsyncAPI) specs that share model types, you can generate them into separate namespaces while avoiding model duplication:
# Step 1: Generate REST API (models + HTTP client) in main namespace
autosdk generate openapi.yaml \
--namespace MyApi \
--clientClassName MyApiClient \
--output Generated
# Step 2: Generate WebSocket client referencing existing REST types
autosdk generate asyncapi.yaml \
--namespace MyApi.Realtime \
--websocket-class-name MyRealtimeClient \
--types-namespace MyApi \
--generate-models false \
--json-serializer-context MyApi.SourceGenerationContext \
--output Generated
Key options:
--types-namespace <ns>— Generated WebSocket client usesglobal::<ns>.{TypeName}references instead of its own namespace--generate-models false— Skips model/enum/converter generation (they already exist in the types namespace)--json-serializer-context <ctx>— References an existingJsonSerializerContextfrom the types namespace--websocket-class-name <name>— Overrides the generated WebSocket client class name
Note: AsyncAPI schema names must match the target namespace's type names. If they differ (e.g., OpenAI where AsyncAPI uses different names), use separate namespaces with full model generation instead.
Real-world examples
- tryAGI/OpenAI — REST API + Realtime WebSocket API
- tryAGI/ElevenLabs — REST API + Realtime Speech-to-Text WebSocket API
- tryAGI/Xai — REST API + Realtime Voice Agent WebSocket API
🤖 Claude Code Skill
AutoSDK is available as a Claude Code skill via skills.sh, enabling AI-assisted SDK generation directly from your terminal.
Install
npx skills add tryAGI/AutoSDK@generating-dotnet-sdks
Usage
Once installed, you can use natural language prompts in Claude Code like:
- "Generate a C# SDK from this OpenAPI spec"
- "Scaffold a new AutoSDK project for the Stripe API"
- "Help me customize the generated client with streaming support"
Claude Code will use the skill's knowledge of AutoSDK CLI options, project conventions, and customization patterns to produce correct commands and code.
What's included
The skill provides Claude Code with detailed knowledge of:
- CLI commands and all their options (
generate,init,http,ai spec-from-docs) - Standard project structure and the
generate.shregeneration pattern - AsyncAPI / WebSocket client generation and cross-namespace schema referencing
- Post-generation customization (partial classes, client hooks, trimming support)
- Troubleshooting common issues
Skill source: skills/generating-dotnet-sdks/
📚Examples of use in real SDKs📚
- https://github.com/tryAGI/OpenAI — REST + WebSocket (AsyncAPI)
- https://github.com/tryAGI/ElevenLabs — REST + WebSocket (AsyncAPI)
- https://github.com/tryAGI/Xai — REST + WebSocket (AsyncAPI)
- https://github.com/tryAGI/Ollama
- https://github.com/tryAGI/Anthropic
- https://github.com/tryAGI/LangSmith
- https://github.com/tryAGI/Replicate
- https://github.com/tryAGI/DeepInfra
- https://github.com/tryAGI/Leonardo
- https://github.com/HavenDV/GitHub.NET
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.30.1-dev.109 | 0 | 3/21/2026 |
| 0.30.1-dev.108 | 0 | 3/21/2026 |
| 0.30.1-dev.107 | 0 | 3/21/2026 |
| 0.30.1-dev.106 | 0 | 3/21/2026 |
| 0.30.1-dev.105 | 0 | 3/21/2026 |
| 0.30.1-dev.104 | 0 | 3/21/2026 |
| 0.30.1-dev.102 | 0 | 3/21/2026 |
| 0.30.1-dev.101 | 0 | 3/21/2026 |
| 0.30.1-dev.100 | 0 | 3/21/2026 |
| 0.30.1-dev.99 | 0 | 3/21/2026 |
| 0.30.1-dev.98 | 0 | 3/21/2026 |
| 0.30.1-dev.97 | 0 | 3/21/2026 |
| 0.30.1-dev.96 | 0 | 3/21/2026 |
| 0.30.1-dev.95 | 0 | 3/21/2026 |
| 0.30.1-dev.94 | 0 | 3/21/2026 |
| 0.30.1-dev.93 | 0 | 3/21/2026 |
| 0.30.1-dev.92 | 0 | 3/21/2026 |
| 0.30.1-dev.91 | 0 | 3/21/2026 |
| 0.30.1-dev.90 | 0 | 3/21/2026 |
| 0.30.0 | 349 | 3/15/2026 |
⭐ Last 10 features:
- feat: Add const discriminator support for AsyncAPI specs 2026-03-21
- feat: Add unit tests for DeriveNameFromMethodAndPath and strip more version prefixes 2026-03-21
- feat: Derive request/response type names from method+path when operationId is missing (#181) 2026-03-21
- feat: Support multi-channel AsyncAPI specs (#183) 2026-03-21
- docs: Add AsyncAPI / WebSocket support documentation to README 2026-03-21
- feat: Enable UseExtensionNaming by default with proper sub-client generation 2026-03-21
- feat: Support 14 OpenAPI x- extensions for improved SDK generation 2026-03-20
- feat: Add discriminated union support for WebSocket receive events 2026-03-20
- feat: Add AsyncAPI spec support for WebSocket client code generation 2026-03-19
- feat: Add EXAMPLES markers to README.md template 2026-03-19
🐞 Last 10 bug fixes:
- fix: Use CSharpTypeNullability for AnyOf ?. operator too 2026-03-21
- fix: Use CSharpTypeNullability instead of IsRequired for enum ?. operator (#179) 2026-03-21
- fix: Handle bool in AnyOf ToString, add tests, remove dead code 2026-03-21
- fix: Serialize bool query params as lowercase 'true'/'false' 2026-03-21
- perf: Cache compiled regex in MethodAndPathGenerator 2026-03-21
- fix: Normalize trailing slashes in path-derived type names 2026-03-21
- feat: Add unit tests for DeriveNameFromMethodAndPath and strip more version prefixes 2026-03-21
- docs: Clarify --websocket-class-name behavior for multi-channel specs 2026-03-21
- perf: Extract keyword escape dictionary, fix CA warnings, add benchmark test 2026-03-21
- perf: Replace remaining LINQ, fix ComputeEnum ToUpperInvariant, pre-size operation lists 2026-03-21