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

Go

SDK गाइड

Go

api14 के साथ openai-go इस्तेमाल करें: base URL सेट करें, चैट, स्ट्रीमिंग, टूल कॉलिंग, स्ट्रक्चर्ड आउटपुट, एम्बेडिंग, त्रुटियाँ और टाइमआउट के Go उदाहरण।

api14 के साथ आधिकारिक openai-go लाइब्रेरी इस्तेमाल करें। option.WithBaseURL को api14 की ओर इंगित करें और कोई भी मॉडल id (उदाहरण के लिए openai/gpt-5-mini) मॉडल के रूप में पास करें।

इंस्टॉल करें

go get github.com/openai/openai-go
export API14_API_KEY="sk-api14-..."

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

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/openai/openai-go"
	"github.com/openai/openai-go/option"
)

var client = openai.NewClient(
	option.WithBaseURL("https://api14.com/api/v1/"),
	option.WithAPIKey(os.Getenv("API14_API_KEY")),
)

var ctx = context.Background()

// नीचे के स्निपेट func main() के अंदर चलते हैं।

बिना विकल्प के openai.NewClient() OPENAI_BASE_URL और OPENAI_API_KEY पढ़ता है, इसलिए आप इसे एनवायरनमेंट से भी कॉन्फ़िगर कर सकते हैं:

export OPENAI_BASE_URL="https://api14.com/api/v1/"
export OPENAI_API_KEY="sk-api14-..."

चैट

resp, err := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
	Model: "openai/gpt-5-mini",
	Messages: []openai.ChatCompletionMessageParamUnion{
		openai.UserMessage("Explain vector databases in two sentences."),
	},
})
if err != nil {
	panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)

स्ट्रीमिंग

stream := client.Chat.Completions.NewStreaming(ctx, openai.ChatCompletionNewParams{
	Model:    "anthropic/claude-sonnet-4.5",
	Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("Write a haiku about APIs.")},
})
for stream.Next() {
	chunk := stream.Current()
	if len(chunk.Choices) > 0 {
		fmt.Print(chunk.Choices[0].Delta.Content)
	}
}
if err := stream.Err(); err != nil {
	panic(err)
}

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

टूल कॉलिंग

params := openai.ChatCompletionNewParams{
	Model:    "openai/gpt-5-mini",
	Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("What's the weather in Istanbul?")},
	Tools: []openai.ChatCompletionToolParam{{
		Function: openai.FunctionDefinitionParam{
			Name:        "get_weather",
			Description: openai.String("Current weather for a city"),
			Parameters: openai.FunctionParameters{
				"type":       "object",
				"properties": map[string]any{"city": map[string]string{"type": "string"}},
				"required":   []string{"city"},
			},
		},
	}},
}

for {
	resp, err := client.Chat.Completions.New(ctx, params)
	if err != nil {
		panic(err)
	}
	msg := resp.Choices[0].Message
	if len(msg.ToolCalls) == 0 {
		fmt.Println(msg.Content)
		break
	}
	params.Messages = append(params.Messages, msg.ToParam())
	for _, call := range msg.ToolCalls {
		var args struct{ City string }
		json.Unmarshal([]byte(call.Function.Arguments), &args)
		params.Messages = append(params.Messages, openai.ToolMessage(getWeather(args.City), call.ID))
	}
}

getWeather आपका फ़ंक्शन है जो स्ट्रिंग लौटाता है। देखें टूल कॉलिंग।

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

schema := map[string]any{
	"type": "object",
	"properties": map[string]any{
		"name": map[string]string{"type": "string"},
		"born": map[string]string{"type": "integer"},
	},
	"required":             []string{"name", "born"},
	"additionalProperties": false,
}

resp, err := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
	Model:    "openai/gpt-5-mini",
	Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("Extract: Ada Lovelace, born 1815.")},
	ResponseFormat: openai.ChatCompletionNewParamsResponseFormatUnion{
		OfJSONSchema: &openai.ResponseFormatJSONSchemaParam{
			JSONSchema: openai.ResponseFormatJSONSchemaJSONSchemaParam{
				Name: "person", Schema: schema, Strict: openai.Bool(true),
			},
		},
	},
})

var person struct {
	Name string `json:"name"`
	Born int    `json:"born"`
}
_ = json.Unmarshal([]byte(resp.Choices[0].Message.Content), &person)

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

इमेज इनपुट

resp, err := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
	Model: "google/gemini-2.5-flash",
	Messages: []openai.ChatCompletionMessageParamUnion{
		openai.UserMessage([]openai.ChatCompletionContentPartUnionParam{
			openai.TextContentPart("What is in this picture?"),
			openai.ImageContentPart(openai.ChatCompletionContentPartImageImageURLParam{
				URL: "https://example.com/photo.jpg", // या data:image/png;base64,... URL
			}),
		}),
	},
})

देखें विज़न और फ़ाइलें।

अतिरिक्त पैरामीटर

जिन फ़ील्ड के लिए SDK में टाइप नहीं है, reasoning, provider, models, उन्हें option.WithJSONSet से जोड़ा जाता है:

resp, err := client.Chat.Completions.New(ctx, params,
	option.WithJSONSet("reasoning", map[string]any{"effort": "high"}),
	option.WithJSONSet("provider", map[string]any{"sort": "throughput"}),
)

एम्बेडिंग

emb, err := client.Embeddings.New(ctx, openai.EmbeddingNewParams{
	Model: "openai/text-embedding-3-small",
	Input: openai.EmbeddingNewParamsInputUnion{OfArrayOfStrings: []string{"The quick brown fox", "Lorem ipsum"}},
})
if err == nil {
	fmt.Println(len(emb.Data[0].Embedding))
}

त्रुटियाँ

API त्रुटियाँ *openai.Error के रूप में लौटती हैं, जिसमें HTTP स्टेटस, मशीन Code और कच्ची प्रतिक्रिया होती है:

import "errors"

var apiErr *openai.Error
if errors.As(err, &apiErr) {
	switch apiErr.StatusCode {
	case 402: // insufficient_balance
		fmt.Println("Balance too low, add funds:", apiErr.Code)
	case 429: // rate_limited या daily_limit_reached
		fmt.Println("Retry after", apiErr.Response.Header.Get("Retry-After"), "s:", apiErr.Code)
	}
}

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

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

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

client := openai.NewClient(
	option.WithBaseURL("https://api14.com/api/v1/"),
	option.WithAPIKey(os.Getenv("API14_API_KEY")),
	option.WithMaxRetries(4),
	option.WithRequestTimeout(60*time.Second), // प्रति प्रयास
)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) // सभी प्रयास
defer cancel()

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