You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A .NET 8.0 client library for the AssistantHub REST API. Provides typed models, async methods, streaming support, and structured error handling for all AssistantHub endpoints.
usingAssistantHub.Sdk;usingAssistantHub.Sdk.Models;using(AssistantHubClientclient=newAssistantHubClient("http://localhost:8800","your-api-key")){// List all assistantsList<Assistant>assistants=awaitclient.ListAssistantsAsync();// Send a chat messageChatCompletionRequestrequest=newChatCompletionRequest{Messages=newList<ChatCompletionMessage>{newChatCompletionMessage{Role="user",Content="Hello!"}}};ChatCompletionResponseresponse=awaitclient.SendMessageAsync(assistants[0].Id,request);Console.WriteLine(response.Choices[0].Message.Content);}
All API calls require an API key passed to the client constructor:
usingAssistantHub.Sdk;// Client creates and owns its own HttpClientusing(AssistantHubClientclient=newAssistantHubClient("http://localhost:8800","your-api-key")){// Use client...}// Or provide your own HttpClient (client does not dispose it)using(HttpClienthttpClient=newHttpClient()){using(AssistantHubClientclient=newAssistantHubClient("http://localhost:8800",httpClient,"your-api-key")){// Use client...}}
Assistant Management
usingAssistantHub.Sdk;usingAssistantHub.Sdk.Models;using(AssistantHubClientclient=newAssistantHubClient("http://localhost:8800","your-api-key")){// Create an assistantAssistantassistant=newAssistant{Name="My Assistant",Description="A helpful assistant for answering questions"};Assistantcreated=awaitclient.CreateAssistantAsync(assistant);Console.WriteLine($"Created assistant: {created.Id}");// Get an assistantAssistantfetched=awaitclient.GetAssistantAsync(created.Id);// Update an assistantfetched.Description="Updated description";awaitclient.UpdateAssistantAsync(fetched.Id,fetched);// List all assistantsList<Assistant>assistants=awaitclient.ListAssistantsAsync();// Delete an assistantawaitclient.DeleteAssistantAsync(created.Id);}
Chat (Non-Streaming)
usingAssistantHub.Sdk;usingAssistantHub.Sdk.Models;using(AssistantHubClientclient=newAssistantHubClient("http://localhost:8800","your-api-key")){ChatCompletionRequestrequest=newChatCompletionRequest{Messages=newList<ChatCompletionMessage>{newChatCompletionMessage{Role="user",Content="What is RAG?"}},Temperature=0.7,MaxTokens=1024};// Send without a thread (stateless)ChatCompletionResponseresponse=awaitclient.SendMessageAsync("asst_your-id",request);Console.WriteLine(response.Choices[0].Message.Content);// Send with a thread (conversation history is preserved)stringthreadId=awaitclient.CreateThreadAsync("asst_your-id");ChatCompletionResponsethreadResponse=awaitclient.SendMessageAsync("asst_your-id",request,threadId);// Access retrieval metadata and citationsif(threadResponse.Retrieval!=null){Console.WriteLine($"Retrieval took {threadResponse.Retrieval.DurationMs}ms");}if(threadResponse.Citations!=null){foreach(CitationSourcesourceinthreadResponse.Citations.Sources){Console.WriteLine($" [{source.Index}] {source.DocumentName} (score: {source.Score})");}}}
Attached-Document Chat
EnumerationResult<AssistantDocumentSelectionItem>selectable=awaitclient.ListAssistantDocumentsAsync("asst_your-id",query:null,searchQuery:"guide",contentType:"application/pdf");stringdocumentId=selectable.Objects[0].Id;ChatCompletionResponseresponse=awaitclient.SendMessageAsync("asst_your-id",newChatCompletionRequest{Messages=newList<ChatCompletionMessage>{newChatCompletionMessage{Role="user",Content="Summarize this document."}},AttachedDocumentIds=newList<string>{documentId}});ChatCompletionResponselocalResponse=awaitclient.SendMessageAsync("asst_your-id",newChatCompletionRequest{Messages=newList<ChatCompletionMessage>{newChatCompletionMessage{Role="user",Content="Summarize this local file."}},LocalAttachments=newList<ChatLocalAttachment>{newChatLocalAttachment{Name="notes.txt",ContentType="text/plain",Base64Content="VGhpcyBpcyBhIGxvY2FsIGZpbGUu"}}});
LocalAttachments require assistant document attachments to be enabled. They are processed for the chat request only and are not added to the assistant collection.
Chat (Streaming)
The SDK provides IAsyncEnumerable<string> for streaming responses. Each yielded string is a raw JSON chunk from the SSE stream.
usingAssistantHub.Sdk;usingAssistantHub.Sdk.Models;using(AssistantHubClientclient=newAssistantHubClient("http://localhost:8800","your-api-key")){// Upload a document from a byte arraybyte[]content=File.ReadAllBytes("document.pdf");AssistantDocumentuploaded=awaitclient.UploadDocumentAsync("irule_your-rule-id",content,"document.pdf","application/pdf");Console.WriteLine($"Uploaded: {uploaded.Id}, Status: {uploaded.Status}");// Upload from a streamusing(FileStreamstream=File.OpenRead("large-file.pdf")){AssistantDocumentstreamUploaded=awaitclient.UploadDocumentAsync("irule_your-rule-id",stream,"large-file.pdf","application/pdf");}// List documents with paginationEnumerationQueryquery=newEnumerationQuery{MaxResults=10};EnumerationResult<AssistantDocument>documents=awaitclient.ListDocumentsAsync(query);foreach(AssistantDocumentdocindocuments.Objects){Console.WriteLine($" {doc.OriginalFilename} - {doc.Status}");}// Search documentsChatCompletionRequestsearchRequest=newChatCompletionRequest{Messages=newList<ChatCompletionMessage>{newChatCompletionMessage{Role="user",Content="quarterly revenue"}}};ChatCompletionResponseresults=awaitclient.SearchAsync("asst_your-id",searchRequest);}
Repository settings are polymorphic. Use WebCrawlRepositorySettings, CifsCrawlRepositorySettings, or NfsCrawlRepositorySettings with the matching RepositoryTypeEnum value.
The AssistantHub server URL (e.g., http://localhost:8800)
apiKey
string
No
API key for authentication
httpClient
HttpClient
No
An externally-managed HttpClient instance
When you provide your own HttpClient, the client will not dispose it -- you are responsible for its lifecycle. When the client creates its own HttpClient, it will be disposed when the client is disposed.
JSON Serialization
The SDK uses System.Text.Json with the following defaults:
Case-insensitive property matching
Null values are ignored during serialization
Enums are serialized as strings (via JsonStringEnumConverter)
Requirements
.NET 8.0 or later
System.Text.Json 8.0.5 (included as a package dependency)