हम cookies इस्तेमाल करते हैं. Cookies और ब्राउज़र स्टोरेज आपको साइन इन रखते हैं और आपकी प्राथमिकताएं याद रखते हैं। आपकी अनुमति से हम यह भी मापते हैं कि साइट कैसे इस्तेमाल होती है। आप कभी भी । हमारी cookie नीति देखें।

C# / .NET

SDK गाइड

C# / .NET

api14 के साथ आधिकारिक OpenAI .NET पैकेज इस्तेमाल करें: Endpoint सेट करें, चैट, स्ट्रीमिंग, टूल कॉलिंग, स्ट्रक्चर्ड आउटपुट, एम्बेडिंग और रीट्राई।

api14 के साथ आधिकारिक OpenAI .NET लाइब्रेरी इस्तेमाल करें। OpenAIClientOptions.Endpoint को api14 पर सेट करें और क्लाइंट बनाते समय openai/gpt-5-mini जैसा मॉडल id पास करें।

इंस्टॉल करें

dotnet add package OpenAI
export API14_API_KEY="sk-api14-..."

कॉन्फ़िगर करें

using System.ClientModel;
using OpenAI;
using OpenAI.Chat;

var credential = new ApiKeyCredential(Environment.GetEnvironmentVariable("API14_API_KEY")!);
var options = new OpenAIClientOptions { Endpoint = new Uri("https://api14.com/api/v1") };

var client = new ChatClient(model: "openai/gpt-5-mini", credential: credential, options: options);

हर ChatClient एक मॉडल से बँधा होता है; जितने मॉडल id इस्तेमाल करें उतने क्लाइंट बनाएँ।

कुंजी को एनवायरनमेंट, user secrets या अपने सीक्रेट स्टोर से पढ़ें, सोर्स कंट्रोल में कमिट हुई appsettings.json से कभी नहीं। ASP.NET Core में एक क्लाइंट को singleton के रूप में रजिस्टर करें; वह thread-safe है।

चैट

ChatCompletion completion = await client.CompleteChatAsync("Explain vector databases in two sentences.");
Console.WriteLine(completion.Content[0].Text);

सिस्टम प्रॉम्प्ट के साथ:

ChatCompletion completion = await client.CompleteChatAsync(
[
    new SystemChatMessage("You are terse."),
    new UserChatMessage("What is RAG?"),
]);

स्ट्रीमिंग

var claude = new ChatClient("anthropic/claude-sonnet-4.5", credential, options);

await foreach (StreamingChatCompletionUpdate update in claude.CompleteChatStreamingAsync("Write a haiku about APIs."))
{
    foreach (ChatMessageContentPart part in update.ContentUpdate)
        Console.Write(part.Text);
}

देखें स्ट्रीमिंग।

टूल कॉलिंग

using System.Text.Json;

ChatTool getWeather = ChatTool.CreateFunctionTool(
    functionName: "get_weather",
    functionDescription: "Current weather for a city",
    functionParameters: BinaryData.FromString("""
        { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] }
        """));

var toolOptions = new ChatCompletionOptions { Tools = { getWeather } };
List<ChatMessage> messages = [new UserChatMessage("What's the weather in Istanbul?")];

ChatCompletion completion = await client.CompleteChatAsync(messages, toolOptions);
while (completion.FinishReason == ChatFinishReason.ToolCalls)
{
    messages.Add(new AssistantChatMessage(completion));
    foreach (ChatToolCall call in completion.ToolCalls)
    {
        using JsonDocument args = JsonDocument.Parse(call.FunctionArguments);
        string city = args.RootElement.GetProperty("city").GetString()!;
        messages.Add(new ToolChatMessage(call.Id, GetWeather(city))); // आपका फ़ंक्शन
    }
    completion = await client.CompleteChatAsync(messages, toolOptions);
}
Console.WriteLine(completion.Content[0].Text);

देखें टूल कॉलिंग।

स्ट्रक्चर्ड आउटपुट

var jsonOptions = new ChatCompletionOptions
{
    ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat(
        jsonSchemaFormatName: "person",
        jsonSchema: BinaryData.FromString("""
            {
              "type": "object",
              "properties": { "name": { "type": "string" }, "born": { "type": "integer" } },
              "required": ["name", "born"],
              "additionalProperties": false
            }
            """),
        jsonSchemaIsStrict: true),
};

ChatCompletion result = await client.CompleteChatAsync(
    [new UserChatMessage("Extract: Ada Lovelace, born 1815.")], jsonOptions);

using JsonDocument person = JsonDocument.Parse(result.Content[0].Text);
Console.WriteLine(person.RootElement.GetProperty("born").GetInt32());

देखें स्ट्रक्चर्ड आउटपुट।

इमेज इनपुट

var vision = new ChatClient("google/gemini-2.5-flash", credential, options);

ChatCompletion described = await vision.CompleteChatAsync(
[
    new UserChatMessage(
        ChatMessageContentPart.CreateTextPart("What is in this picture?"),
        ChatMessageContentPart.CreateImagePart(new Uri("https://example.com/photo.jpg"))),
]);

लोकल फ़ाइल के लिए ChatMessageContentPart.CreateImagePart(BinaryData.FromBytes(File.ReadAllBytes("photo.png")), "image/png") इस्तेमाल करें। देखें विज़न और फ़ाइलें।

एम्बेडिंग

using OpenAI.Embeddings;

var embeddings = new EmbeddingClient("openai/text-embedding-3-small", credential, options);
OpenAIEmbedding embedding = await embeddings.GenerateEmbeddingAsync("The quick brown fox");
Console.WriteLine(embedding.ToFloats().Length);

त्रुटियाँ

विफल कॉल ClientResultException throw करती हैं; कच्ची प्रतिक्रिया में स्टेटस और हेडर होते हैं:

try
{
    await client.CompleteChatAsync("Hi");
}
catch (ClientResultException ex) when (ex.Status == 402)
{
    Console.Error.WriteLine("Balance too low, add funds (insufficient_balance).");
}
catch (ClientResultException ex) when (ex.Status == 429)
{
    string? retryAfter = null;
    ex.GetRawResponse()?.Headers.TryGetValue("Retry-After", out retryAfter);
    Console.Error.WriteLine($"Rate limited, retry after {retryAfter ?? "60"}s.");
}

देखें त्रुटियाँ।

टाइमआउट और रीट्राई

लाइब्रेरी 429 और 5xx को exponential backoff के साथ अपने आप दोबारा आज़माती है। रीट्राई की संख्या और नेटवर्क टाइमआउट को उन options पर ट्यून करें जो आप हर क्लाइंट को देते हैं:

using System.ClientModel.Primitives;

var options = new OpenAIClientOptions
{
    Endpoint = new Uri("https://api14.com/api/v1"),
    NetworkTimeout = TimeSpan.FromMinutes(2),
    RetryPolicy = new ClientRetryPolicy(maxRetries: 4),
};

रीट्राई के दौरान कुल समय सीमित करने के लिए किसी भी ...Async कॉल को CancellationToken पास करें। daily_limit_reached या insufficient_balance में रीट्राई से मदद नहीं मिलती। देखें रेट लिमिट।

सभी क्षमताएँ

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.chat.completions.create({
  "model": "openai/gpt-5-mini",
  "messages": [
    {
      "role": "user",
      "content": "Explain vector databases in two sentences."
    }
  ]
});
console.log(result.choices[0].message.content);