The Upstage SDK implements IChatClient and IEmbeddingGenerator<string, Embedding<float>> and provides AIFunction tool wrappers, all compatible with Microsoft.Extensions.AI.
Installation
1
dotnetaddpackageUpstage
Namespace Note
The Upstage SDK has its own IChatClient and ChatMessage types that conflict with Microsoft.Extensions.AI. Use the Meai alias:
1
usingMeai=Microsoft.Extensions.AI;
Chat Completions
UpstageClient implements IChatClient, so you can use it with the standard MEAI interface.
1 2 3 4 5 6 7 8 910
usingUpstage;usingMeai=Microsoft.Extensions.AI;Meai.IChatClientclient=newUpstageClient(apiKey:Environment.GetEnvironmentVariable("UPSTAGE_API_KEY")!);varresponse=awaitclient.GetResponseAsync("What is the capital of France?",newMeai.ChatOptions{ModelId="solar-pro"});Console.WriteLine(response.Text);
Streaming
1 2 3 4 5 6 7 8 91011
usingUpstage;usingMeai=Microsoft.Extensions.AI;Meai.IChatClientclient=newUpstageClient(apiKey:Environment.GetEnvironmentVariable("UPSTAGE_API_KEY")!);awaitforeach(varupdateinclient.GetStreamingResponseAsync("Explain quantum computing in simple terms.",newMeai.ChatOptions{ModelId="solar-pro"})){Console.Write(update.Text);}
usingUpstage;usingMeai=Microsoft.Extensions.AI;Meai.IChatClientclient=newUpstageClient(apiKey:Environment.GetEnvironmentVariable("UPSTAGE_API_KEY")!);vartool=Meai.AIFunctionFactory.Create((stringlocation)=>$"The weather in {location} is sunny, 22C.","GetWeather","Gets the current weather for a given location.");varoptions=newMeai.ChatOptions{ModelId="solar-pro",Tools=[tool],};varmessages=newList<Meai.ChatMessage>{new(Meai.ChatRole.User,"What is the weather in Seoul?"),};while(true){varresponse=awaitclient.GetResponseAsync(messages,options);messages.AddRange(response.ToChatMessages());if(response.FinishReason==Meai.ChatFinishReason.ToolCalls){varresults=awaitresponse.CallToolsAsync(options);messages.AddRange(results);continue;}Console.WriteLine(response.Text);break;}
Embeddings
UpstageClient implements IEmbeddingGenerator<string, Embedding<float>> for text embeddings.
The SDK provides AIFunction tool wrappers for Upstage's unique capabilities, usable with any IChatClient:
Groundedness Check
Verify whether an answer is factually supported by a given context.
1 2 3 4 5 6 7 8 91011121314
usingUpstage;usingMeai=Microsoft.Extensions.AI;varupstage=newUpstageClient(apiKey:Environment.GetEnvironmentVariable("UPSTAGE_API_KEY")!);vargroundednessTool=upstage.AsGroundednessCheckTool();// Use with any IChatClientMeai.IChatClientchatClient=/* any IChatClient */;varoptions=newMeai.ChatOptions{Tools=[groundednessTool],};
Translation
Translate text between languages using Solar translation models.
1234567
usingUpstage;varupstage=newUpstageClient(apiKey:Environment.GetEnvironmentVariable("UPSTAGE_API_KEY")!);vartranslateTool=upstage.AsTranslateTool();// Supports English-Korean and other language pairs
Document Parse
Parse documents (PDFs, images) and extract structured content.