XaiProtoSharp
Auto-generated C# gRPC client for the xAI API, built from protobuf definitions in xai-org/xai-proto.
Disclaimer: This is an unofficial, community-maintained project. All library code is auto-generated from upstream protobuf definitions and is provided as-is with no guarantee of functionality. This project is not affiliated with or endorsed by xAI. Use at your own risk.
API Reference
Browse the full API Reference for detailed documentation of all types, services, and methods.
Installation
Install via NuGet:
dotnet add package XaiProtoSharp
Quick Start
using Grpc.Core;
using Grpc.Net.Client;
using XaiApi;
// Create a gRPC channel
var channel = GrpcChannel.ForAddress("https://api.x.ai");
var client = new Chat.ChatClient(channel);
// Authenticate with your API key
var headers = new Metadata
{
{ "Authorization", $"Bearer {apiKey}" }
};
// Send a chat completion request
var request = new GetCompletionsRequest
{
Model = "grok-4-1-fast-reasoning",
Messages =
{
new Message
{
Content = { new Content { Text = "Hello, world!" } },
Role = MessageRole.RoleUser
}
},
MaxTokens = 100
};
var response = client.GetCompletion(request, headers);
foreach (var output in response.Outputs)
{
Console.WriteLine(output.Message.Content);
}
Supported Frameworks
- .NET 8.0
- .NET 9.0
- .NET 10.0
Building from Source
Prerequisites: .NET 10.0 SDK, Buf CLI (for code generation only)
# Build
dotnet build XaiProtoSharp.slnx
# Run tests (requires XAI_API_KEY environment variable)
dotnet test Xai.Protos.Test
To regenerate the gRPC client code from upstream protobuf definitions:
git clone https://github.com/xai-org/xai-proto.git xai-proto
buf generate xai-proto
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.