AutoSDK
Guides

AsyncAPI & WebSockets

Generate WebSocket clients from AsyncAPI specs with cross-namespace schema referencing.

AutoSDK generates typed WebSocket clients from AsyncAPI specifications, with full support for cross-namespace schema referencing to avoid model duplication.

Basic AsyncAPI Generation

autosdk generate asyncapi.json \
  --namespace MyCompany.MyApi.Realtime \
  --output Generated

This generates a WebSocket client with typed Send* and Receive* methods for each channel.

Cross-Namespace Schema Referencing

When your API has both REST (OpenAPI) and WebSocket (AsyncAPI) endpoints sharing the same model types, use cross-namespace referencing to avoid duplicating models:

Step 1: Generate REST API (models + HTTP client)

autosdk generate openapi.yaml \
  --namespace MyCompany.MyApi \
  --output Generated

Step 2: Generate WebSocket Client (no models — references REST types)

autosdk generate asyncapi.json \
  --namespace MyCompany.MyApi.Realtime \
  --types-namespace MyCompany.MyApi \
  --generate-models false \
  --json-serializer-context MyCompany.MyApi.SourceGenerationContext \
  --output Generated

Key Options

OptionPurpose
--types-namespaceGenerated WebSocket code uses global::MyCompany.MyApi.TypeName references
--generate-models falseSkip model/enum/converter generation (they exist in the REST namespace)
--json-serializer-contextReference the existing JsonSerializerContext from the REST project

Constraint

AsyncAPI schema names must match the target namespace's type names exactly. If names differ (e.g., OpenAI's AsyncAPI uses different names than its REST API), generate separate namespaces with full model generation instead.

Real-World Examples

OpenAI Realtime API

OpenAI has both REST and Realtime WebSocket APIs:

# REST API
autosdk generate openapi.yaml \
  --namespace tryAGI.OpenAI \
  --output Generated

# Realtime WebSocket (separate namespace — schema names differ)
autosdk generate asyncapi.json \
  --namespace tryAGI.OpenAI.Realtime \
  --output Generated

ElevenLabs Speech-to-Text

ElevenLabs shares types between REST and WebSocket:

# REST API
autosdk generate openapi.yaml \
  --namespace tryAGI.ElevenLabs \
  --output Generated

# WebSocket STT (references REST types)
autosdk generate asyncapi.json \
  --namespace tryAGI.ElevenLabs.Realtime \
  --types-namespace tryAGI.ElevenLabs \
  --generate-models false \
  --json-serializer-context tryAGI.ElevenLabs.SourceGenerationContext \
  --output Generated

SDKs with Dual Specs

SDKREST (OpenAPI)WebSocket (AsyncAPI)Cross-Namespace?
OpenAIREST APIRealtime voice/textNo (different schema names)
ElevenLabsREST APIRealtime STTYes
XaiREST APIRealtimeYes
Edit on GitHub

Last updated on

On this page