- Fully generated C# SDK based on official Coze OpenAPI specification using AutoSDK
- Same day update to support new features
- Updated and supported automatically if there are no breaking changes
- All modern .NET features - nullability, trimming, NativeAOT, etc.
- Support .Net Framework/.Net Standard 2.0
- Microsoft.Extensions.AI
IChatClientsupport for bot-based chat
using Coze;
using var client = new CozeClient(apiKey);The SDK implements IChatClient:
using Coze;
using Microsoft.Extensions.AI;
var botId = Environment.GetEnvironmentVariable("COZE_BOT_ID")!;
IChatClient chatClient = new CozeClient(apiKey)
.WithBotId(botId)
.WithUserId("demo-user");
var response = await chatClient.GetResponseAsync(
[new ChatMessage(ChatRole.User, "Reply with only the word ok.")]);
Console.WriteLine(response.Text);Coze chat is bot-centric. You must provide a bot_id via WithBotId(...), ChatOptions.ModelId, or ChatOptions.AdditionalProperties["bot_id"].
Basic example showing how to create a client and make a request.
using var client = new CozeClient(apiKey);Examples of listing published bots in a workspace.
// To list bots, you need a workspace (space) ID. You can find your workspace ID
// in the Coze dashboard URL when viewing your workspace.
var workspaceId =
Environment.GetEnvironmentVariable("COZE_WORKSPACE_ID") is { Length: > 0 } value
? value
: throw new AssertInconclusiveException("COZE_WORKSPACE_ID environment variable is not found.");
using var client = new CozeClient(apiKey);
// List published bots in the workspace using `GetSpacePublishedBotsListAsync`.
// This returns bots that have been published and are available for use.
var response = await client.GetSpacePublishedBotsListAsync(
spaceId: workspaceId,
pageSize: 10);
// The response contains a `Code` field (0 means success) and a `Data` field
// with the list of bots and total count.
// Each bot in the list has a `BotId`, `BotName`, and optional `Description`.
if (response.Data.SpaceBots is { Count: > 0 } bots)
{
var firstBot = bots[0];
Console.WriteLine($"First bot: {firstBot.BotName} (ID: {firstBot.BotId})");
}Examples of listing workflows in a workspace.
// To list workflows, you need a workspace ID. You can find your workspace ID
// in the Coze dashboard URL when viewing your workspace.
var workspaceId =
Environment.GetEnvironmentVariable("COZE_WORKSPACE_ID") is { Length: > 0 } value
? value
: throw new AssertInconclusiveException("COZE_WORKSPACE_ID environment variable is not found.");
using var client = new CozeClient(apiKey);
// List workflows in the workspace using `OpenAPIGetWorkflowListAsync`.
// The `pageNum` parameter starts at 1 (one-based pagination).
var response = await client.OpenAPIGetWorkflowListAsync(
workspaceId: workspaceId,
pageNum: 1,
pageSize: 10);
// The response contains a `Code` field (0 means success) and a `Data` field
// with the workflow items and pagination info.
// Each workflow has a `WorkflowId`, `WorkflowName`, and optional `Description`.
foreach (var workflow in response.Data.Items)
{
Console.WriteLine($"Workflow: {workflow.WorkflowName} (ID: {workflow.WorkflowId})");
}
Console.WriteLine($"Has more: {response.Data.HasMore}");Priority place for bugs: https://github.com/tryAGI/Coze/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Coze/discussions
Discord: https://discord.gg/Ca2xhfBf3v
This project is supported by JetBrains through the Open Source Support Program.
