- Fully generated C# SDK based on official DeepInfra 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
- Support all DeepInfra API endpoints including Object Detection, Token Classification, Image Classification, Fill Mask and more.
- Microsoft.Extensions.AI
IChatClientandIEmbeddingGeneratorsupport viatryAGI.OpenAICustomProviders
To interact with the OpenAI like API, you need to use tryAGI.OpenAI library:
<PackageReference Include="tryAGI.OpenAI" Version="3.7.0" />
usingOpenAI;usingvarclient=CustomProviders.DeepInfra(apiKey);varenumerable=api.Chat.CreateChatCompletionAsStreamAsync(model:"meta-llama/Meta-Llama-3-8B-Instruct",messages:["What is the capital of the United States?"]);awaitforeach(varresponseinenumerable){Console.Write(response.Choices[0].Delta.Content);}DeepInfra provides an OpenAI-compatible API. For IChatClient and IEmbeddingGenerator support via Microsoft.Extensions.AI, use the tryAGI.OpenAI package:
dotnet add package tryAGI.OpenAI
usingOpenAI;usingMicrosoft.Extensions.AI;usingvarclient=CustomProviders.DeepInfra(apiKey);// IChatClientIChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync("Hello!",newChatOptions{ModelId="Qwen/Qwen2.5-72B-Instruct"});// IEmbeddingGeneratorIEmbeddingGenerator<string,Embedding<float>>generator=client;varembeddings=awaitgenerator.GenerateAsync(["Hello, world!"],newEmbeddingGenerationOptions{ModelId="BAAI/bge-en-icl"});dotnet tool install --global DeepInfra.CLI --prerelease
deep-infra api --helpusingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([newMeai.ChatMessage(Meai.ChatRole.User,"Say hello in exactly 3 words.")],newMeai.ChatOptions{ModelId=DeepInfraModel});vartext=response.Messages[0].Text;Console.WriteLine(text);usingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;varupdates=newList<Meai.ChatResponseUpdate>();awaitforeach(varupdateinchatClient.GetStreamingResponseAsync([newMeai.ChatMessage(Meai.ChatRole.User,"Count from 1 to 5.")],newMeai.ChatOptions{ModelId=DeepInfraModel})){updates.Add(update);vartext=string.Concat(update.Contents.OfType<Meai.TextContent>().Select(c =>c.Text));if(!string.IsNullOrEmpty(text)){Console.Write(text);}}Console.WriteLine();usingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([newMeai.ChatMessage(Meai.ChatRole.User,"Say 'hi'.")],newMeai.ChatOptions{ModelId=DeepInfraModel});Console.WriteLine($"Input: {response.Usage.InputTokenCount}, Output: {response.Usage.OutputTokenCount}, Total: {response.Usage.TotalTokenCount}");usingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;vartool=Meai.AIFunctionFactory.Create((stringcity)=>cityswitch{"Paris"=>"22°C, sunny","London"=>"15°C, cloudy",
_ =>"Unknown",},name:"GetWeather",description:"Gets the current weather for a city");varchatOptions=newMeai.ChatOptions{ModelId=DeepInfraModel,Tools=[tool],};varmessages=newList<Meai.ChatMessage>{new(Meai.ChatRole.User,"What's the weather in Paris? Respond with the temperature only."),};// First turn — get tool callvarresponse=awaitchatClient.GetResponseAsync((IEnumerable<Meai.ChatMessage>)messages,chatOptions);varfunctionCall=response.Messages.SelectMany(m =>m.Contents).OfType<Meai.FunctionCallContent>().First();// Execute tool and add resultvartoolResult=awaittool.InvokeAsync(functionCall.Argumentsis{}args?newMeai.AIFunctionArguments(args):null);messages.AddRange(response.Messages);messages.Add(newMeai.ChatMessage(Meai.ChatRole.Tool,newMeai.AIContent[]{newMeai.FunctionResultContent(functionCall.CallId,toolResult),}));// Second turn — get final responsevarfinalResponse=awaitchatClient.GetResponseAsync((IEnumerable<Meai.ChatMessage>)messages,chatOptions);vartext=finalResponse.Messages[0].Text;Console.WriteLine($"Final response: {text}");usingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;vartool=Meai.AIFunctionFactory.Create((stringcity)=>cityswitch{"Paris"=>"22°C, sunny","London"=>"15°C, cloudy",
_ =>"Unknown",},name:"GetWeather",description:"Gets the current weather for a city");varresponse=awaitchatClient.GetResponseAsync([newMeai.ChatMessage(Meai.ChatRole.User,"What's the weather in Paris?")],newMeai.ChatOptions{ModelId=DeepInfraModel,Tools=[tool],});varfunctionCall=response.Messages.SelectMany(m =>m.Contents).OfType<Meai.FunctionCallContent>().FirstOrDefault();Console.WriteLine($"Tool call: {functionCall.Name}({string.Join(", ",functionCall.Arguments?.Select(kv =>$"{kv.Key}={kv.Value}")??[])})");usingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([newMeai.ChatMessage(Meai.ChatRole.System,"You always respond with exactly one word."),newMeai.ChatMessage(Meai.ChatRole.User,"What color is the sky?"),],newMeai.ChatOptions{ModelId=DeepInfraModel});vartext=response.Messages[0].Text;Console.WriteLine(text);// Use the OpenAI SDK via CustomProviders.DeepInfra() with MEAI interfaceusingvarclient=GetAuthenticatedOpenAiClient();Meai.IChatClientchatClient=client;awaitforeach(varupdateinchatClient.GetStreamingResponseAsync([newMeai.ChatMessage(Meai.ChatRole.User,"What is the capital of the United States?")],newMeai.ChatOptions{ModelId=DeepInfraModel})){vartext=string.Concat(update.Contents.OfType<Meai.TextContent>().Select(c =>c.Text));Console.Write(text);}usingvarclient=GetAuthenticatedOpenAiClient();Meai.IEmbeddingGenerator<string,Meai.Embedding<float>>generator=client;varembeddings=awaitgenerator.GenerateAsync(["First sentence.","Second sentence.","Third sentence."],newMeai.EmbeddingGenerationOptions{ModelId=DeepInfraEmbeddingModel});foreach(varembeddinginembeddings){}Console.WriteLine($"Generated {embeddings.Count} embeddings with {embeddings[0].Vector.Length} dimensions each");usingvarclient=GetAuthenticatedOpenAiClient();Meai.IEmbeddingGenerator<string,Meai.Embedding<float>>generator=client;varembeddings=awaitgenerator.GenerateAsync(["Hello, world!"],newMeai.EmbeddingGenerationOptions{ModelId=DeepInfraEmbeddingModel});Console.WriteLine($"Embedding dimensions: {embeddings[0].Vector.Length}");varclient=newDeepInfraClient(apiKey);varmodels=awaitclient.ModelsListAsync();foreach(varmodelinmodels){Console.WriteLine(model.ModelName);}varclient=newDeepInfraClient(apiKey);Meme=awaitclient.MeAsync();Console.WriteLine($"{me.ToJson(newJsonSerializerOptions{WriteIndented=true,})}");This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.
Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.
Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.
Priority place for bugs: https://github.com/tryAGI/DeepInfra/issues
Priority place for ideas and general questions: https://github.com/tryAGI/DeepInfra/discussions
Discord: https://discord.gg/Ca2xhfBf3v
This project is supported by JetBrains through the Open Source Support Program.
