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

Node.js

SDK गाइड

Node.js

api14 के साथ आधिकारिक openai npm पैकेज इस्तेमाल करें: इंस्टॉल, कॉन्फ़िगरेशन, चैट, स्ट्रीमिंग, टूल कॉलिंग, एम्बेडिंग, त्रुटियाँ और रीट्राई।

api14 के साथ आधिकारिक openai npm पैकेज इस्तेमाल करें। और कुछ नहीं बदलता: केवल baseURL और apiKey api14 की ओर इशारा करते हैं, और हर मॉडल id model के रूप में काम करता है।

इंस्टॉल करें

npm install openai

अपनी कुंजी को एक एनवायरनमेंट वेरिएबल में रखें:

export API14_API_KEY="sk-api14-..."

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

import OpenAI from "openai";

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

कोई विकल्प न देने पर SDK OPENAI_BASE_URL और OPENAI_API_KEY पढ़ता है। ये दोनों वेरिएबल सेट करने से कोड बदले बिना मौजूदा ऐप api14 पर आ जाता है:

export OPENAI_BASE_URL="https://api14.com/api/v1"
export OPENAI_API_KEY="sk-api14-..."
const client = new OpenAI(); // दोनों वेरिएबल अपने आप उठा लेता है

चैट

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);

स्ट्रीमिंग

const stream = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4.5",
  messages: [{ role: "user", content: "Write a haiku about APIs." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

इवेंट फ़ॉर्मेट के लिए देखें स्ट्रीमिंग।

टूल कॉलिंग

tools भेजें, मॉडल जो कॉल माँगे उन्हें चलाएँ, नतीजे जोड़ें और तब तक दोबारा कॉल करें जब तक वह टेक्स्ट में उत्तर न दे:

const tools = [{
  type: "function",
  function: {
    name: "get_weather",
    description: "Current weather for a city",
    parameters: {
      type: "object",
      properties: { city: { type: "string" } },
      required: ["city"],
    },
  },
}];

const messages = [{ role: "user", content: "What's the weather in Istanbul?" }];
let res = await client.chat.completions.create({ model: "openai/gpt-5-mini", messages, tools });

while (res.choices[0].finish_reason === "tool_calls") {
  const msg = res.choices[0].message;
  messages.push(msg);
  for (const call of msg.tool_calls) {
    const args = JSON.parse(call.function.arguments);
    const result = await getWeather(args.city); // आपका फ़ंक्शन
    messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify(result) });
  }
  res = await client.chat.completions.create({ model: "openai/gpt-5-mini", messages, tools });
}

console.log(res.choices[0].message.content);

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

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

parse हेल्पर एक Zod schema को json_schema रिस्पॉन्स फ़ॉर्मेट में बदलता है और उत्तर को पार्स करता है (npm install zod):

import { z } from "zod";
import { zodResponseFormat } from "openai/helpers/zod";

const Person = z.object({ name: z.string(), born: z.number().int(), city: z.string() });

const res = await client.chat.completions.parse({
  model: "openai/gpt-5-mini",
  messages: [{ role: "user", content: "Extract: Ada Lovelace, born 1815 in London." }],
  response_format: zodResponseFormat(Person, "person"),
});

console.log(res.choices[0].message.parsed); // { name: "Ada Lovelace", born: 1815, city: "London" }

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

इमेज इनपुट

content को पार्ट्स के ऐरे के रूप में पास करें। सार्वजनिक URL या base64 data URL इस्तेमाल करें:

import { readFileSync } from "node:fs";

const image = readFileSync("photo.png").toString("base64");

const res = await client.chat.completions.create({
  model: "google/gemini-2.5-flash",
  messages: [{
    role: "user",
    content: [
      { type: "text", text: "What is in this picture?" },
      { type: "image_url", image_url: { url: `data:image/png;base64,${image}` } },
    ],
  }],
});

PDF, ऑडियो और वीडियो के लिए देखें विज़न और फ़ाइलें।

एम्बेडिंग

const result = await client.embeddings.create({
  model: "openai/text-embedding-3-small",
  input: ["The quick brown fox", "Lorem ipsum"],
});

console.log(result.data.map((d) => d.embedding.length));

बिना SDK मेथड वाले एंडपॉइंट

वीडियो जॉब और rerank OpenAI SDK की सतह का हिस्सा नहीं हैं। क्लाइंट के सामान्य post / get हेल्पर इस्तेमाल करें, वे बेस URL, कुंजी और रीट्राई दोबारा इस्तेमाल करते हैं:

const ranked = await client.post("/rerank", {
  body: {
    model: "cohere/rerank-v3.5",
    query: "What is the capital of France?",
    documents: ["Paris is the capital of France.", "Berlin is in Germany."],
    top_n: 1,
  },
});
console.log(ranked.results);

त्रुटियाँ

त्रुटियाँ OpenAI की संरचना में आती हैं और OpenAI.APIError के रूप में throw होती हैं। status और code पर शाखा बनाएँ:

try {
  await client.chat.completions.create({ model: "openai/gpt-5-mini", messages: [{ role: "user", content: "Hi" }] });
} catch (err) {
  if (err instanceof OpenAI.APIError) {
    if (err.status === 402) console.error("Balance too low, add funds:", err.code); // insufficient_balance
    else if (err.status === 429) console.error("Retry after", err.headers?.["retry-after"], "s:", err.code); // rate_limited
    else throw err;
  }
}

हर कोड के लिए देखें त्रुटियाँ।

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

SDK कनेक्शन त्रुटियों, 408, 409, 429 और 5xx प्रतिक्रियाओं को डिफ़ॉल्ट रूप से दो बार दोबारा आज़माता है, exponential backoff के साथ जो Retry-After का सम्मान करता है। डिफ़ॉल्ट टाइमआउट प्रति प्रयास 10 मिनट है। दोनों को क्लाइंट पर सेट करें, या प्रति अनुरोध ओवरराइड करें:

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
  timeout: 60_000, // प्रति प्रयास ms
  maxRetries: 4,
});

await client.chat.completions.create(params, { timeout: 300_000, maxRetries: 0 });

रीट्राई 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);