Skip to content

Chat Completion

Shows how to use the Upstage Solar LLM for chat completions.

This example assumes using Upstage; is in scope and apiKey contains your Upstage API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Create an authenticated client using your Upstage API key.
using var client = new UpstageClient(apiKey);

// Send a simple chat message to the Solar Mini model.
// The `CreateChatCompletionAsync` method accepts a model name and a list of messages.
var response = await client.Chat.CreateChatCompletionAsync(
    model: "solar-mini",
    messages: [
        new ChatMessage
        {
            Role = ChatMessageRole.System,
            Content = "You are a helpful assistant.",
        },
        new ChatMessage
        {
            Role = ChatMessageRole.User,
            Content = "Hello! What is Upstage?",
        },
    ]);

// The response contains a unique ID, the model used, and a list of choices.
// Each choice has a message with the assistant's reply.

Console.WriteLine($"Response: {response.Choices[0].Message!.Content}");