LeapAi.SDK.Providers.xAI
2.0.1
dotnet add package LeapAi.SDK.Providers.xAI --version 2.0.1
NuGet\Install-Package LeapAi.SDK.Providers.xAI -Version 2.0.1
<PackageReference Include="LeapAi.SDK.Providers.xAI" Version="2.0.1" />
<PackageVersion Include="LeapAi.SDK.Providers.xAI" Version="2.0.1" />
<PackageReference Include="LeapAi.SDK.Providers.xAI" />
paket add LeapAi.SDK.Providers.xAI --version 2.0.1
#r "nuget: LeapAi.SDK.Providers.xAI, 2.0.1"
#:package LeapAi.SDK.Providers.xAI@2.0.1
#addin nuget:?package=LeapAi.SDK.Providers.xAI&version=2.0.1
#tool nuget:?package=LeapAi.SDK.Providers.xAI&version=2.0.1
<p align="center"> <img src="assets/leap_logo.png" alt="Leap AI Logo" width="120"> </p>
LeapAi.SDK.Providers.xAI
<p align="center"> <a href="https://www.nuget.org/packages/LeapAi.SDK.Providers.xAI"><img src="https://img.shields.io/nuget/v/LeapAi.SDK.Providers.xAI.svg" alt="NuGet" /></a> </p>
xAI Grok provider for the Leap AI SDK — a provider-agnostic .NET toolkit for building AI-powered applications, chatbots, and agents against a unified LeapClient.
Installation
dotnet add package LeapAi.SDK.Providers.xAI
You will also need the Core package (pulled in automatically as a transitive dependency):
dotnet add package LeapAi.SDK.Core
Quick Start
using Leap.AI.Core;
using Leap.AI.Providers.xAI;
var leap = LeapClient.Create()
.UseXAi("xai-...") // grok-3 by default
.UseLogging()
.UseRetry(maxRetries: 3)
.Build();
string result = await leap.GenerateTextAsync("Explain the Fermi paradox.");
Console.WriteLine(result);
Supported Models
| Model | Description |
|---|---|
grok-3 (default) |
Most capable — best reasoning and instruction-following |
grok-3-fast |
Speed-optimised variant of Grok 3 |
grok-3-mini |
Lightweight, cost-efficient |
grok-3-mini-fast |
Fastest and smallest |
grok-2 |
Previous-generation model |
Override the model at build time:
var leap = LeapClient.Create()
.UseXAi("xai-...", defaultModel: "grok-3-fast")
.Build();
Or via the options delegate:
var leap = LeapClient.Create()
.UseXAi(o =>
{
o.ApiKey = "xai-...";
o.DefaultModel = "grok-3-mini";
})
.Build();
Usage
Text Generation
string answer = await leap.GenerateTextAsync("What is a transformer model?");
Conversation History
var messages = new List<ChatMessage>
{
ChatMessage.System("You are a concise technical assistant."),
ChatMessage.User("What is xAI's Grok?")
};
var response = await leap.GenerateAsync(messages);
Console.WriteLine(response.Text);
Streaming
await foreach (var chunk in leap.StreamAsync("Write a haiku about AGI."))
{
Console.Write(chunk.Text);
}
Structured Output
public record MarketSummary(string Ticker, double Price, string Sentiment);
var summary = await leap.GenerateObjectAsync<MarketSummary>(
"Summarise the current state of $TSLA in one concise JSON object."
);
Console.WriteLine($"{summary.Ticker}: ${summary.Price} — {summary.Sentiment}");
Tool Calling (Agents)
using Leap.AI.Core.Tools;
public record SearchArgs(string Query);
var searchTool = FunctionTool<SearchArgs>.Create(
name: "web_search",
description: "Searches the web and returns a summary of the top results.",
handler: args => $"Top result for '{args.Query}': ..."
);
var leap = LeapClient.Create()
.UseXAi("xai-...")
.UseTool(searchTool)
.Build();
var response = await leap.GenerateTextAsync("Search for the latest xAI news.");
ASP.NET Core / Dependency Injection
Install the DI extension package:
dotnet add package LeapAi.SDK.Extensions.DependencyInjection
using Leap.AI.Extensions.DependencyInjection;
builder.Services.AddLeap(leap => leap
.UseXAi(builder.Configuration["xAI:ApiKey"]!)
.UseLogging()
.UseRetry(3));
Inject LeapClient anywhere in your app:
public class MyService(LeapClient ai)
{
public Task<string> AskAsync(string q) => ai.GenerateTextAsync(q);
}
Available Packages
| Package | Purpose |
|---|---|
LeapAi.SDK |
All-in-one metapackage |
LeapAi.SDK.Core |
Core abstractions & pipeline |
LeapAi.SDK.Providers.OpenAi |
OpenAI (GPT-4o, o3-mini …) |
LeapAi.SDK.Providers.Anthropic |
Anthropic (Claude 3.5/3.7 …) |
LeapAi.SDK.Providers.Google |
Google (Gemini 2.0 Flash …) |
LeapAi.SDK.Providers.xAI |
xAI (Grok 3 …) |
LeapAi.SDK.Extensions.DependencyInjection |
ASP.NET Core DI |
Community & Contributing
The Leap AI SDK community lives on our GitHub repository. Questions, ideas, and contributions are all welcome!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- LeapAi.SDK.Core (>= 2.0.1)
- LeapAi.SDK.Providers.OpenAi (>= 2.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LeapAi.SDK.Providers.xAI:
| Package | Downloads |
|---|---|
|
LeapAi.SDK
Leap AI SDK v2.0 - A high-performance, provider-agnostic .NET AI orchestrator with middleware pipelines, structured output, and automatic tool calling. This metapackage includes Core and all official providers: OpenAI, Anthropic, Google Gemini, and xAI Grok. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.1 | 112 | 4/30/2026 |