Content पर जाएं

प्रमाणीकरण ​

SandBase सार्वजनिक API अनुरोधों को प्रमाणित करने के लिए API keys का उपयोग करता है। यह पृष्ठ समर्थित एकीकरण विधियों और key-management प्रथाओं को कवर करता है। Console authentication और इसके आंतरिक APIs सार्वजनिक API contract का हिस्सा नहीं हैं।

प्रमाणीकरण विधियाँ ​

मानक SandBase /v1/* endpoints के लिए Bearer token आवश्यक है। Anthropic Messages और Google Gemini-compatible operations अपने native SDK-compatible API key locations को भी स्वीकार करते हैं।

Bearer token ​

Authorization header में key शामिल करें:

http
Authorization: Bearer sk-your-api-key

यह OpenAI-compatible SDKs द्वारा उपयोग की जाने वाली मानक विधि है।

Anthropic Messages: x-api-key header ​

x-api-key header में key शामिल करें:

http
x-api-key: sk-your-api-key

यह header केवल POST /v1/messages द्वारा समर्थित है। अन्य public endpoints इसे extract नहीं करते; Chat Completions, /v1/run, और resource APIs के लिए Bearer authentication का उपयोग करें।

प्राथमिकता ​

केवल POST /v1/messages के लिए, जब दोनों headers मौजूद हों, x-api-key को प्राथमिकता दी जाती है।

Google Gemini-compatible API keys ​

Gemini GenerateContent और Interactions operations x-goog-api-key, Authorization: Bearer …, या key query parameter स्वीकार करते हैं, उसी प्राथमिकता क्रम में। header को प्राथमिकता दें क्योंकि query-string credentials logs और browser history में दिखाई दे सकते हैं। समर्थित paths के लिए Google Gemini और Gemini Interactions देखें।

निष्कर्षण तर्क ​

मानक endpoints केवल Authorization: Bearer <key> पढ़ते हैं। Anthropic Messages middleware पहले x-api-key पढ़ता है और फिर Bearer header पर वापस जाता है। Agents platform resources Authorization: Bearer या X-API-Key स्वीकार करते हैं (नीचे देखें)। webhook Events API (/events/webhooks*) भी दोनों में से कोई भी header स्वीकार करता है और जब दोनों मौजूद हों तो Bearer header का उपयोग करता है। समर्थित credential के अभाव में 401 Unauthorized लौटता है।

Agents platform resources ​

/v1/agents* (जिसमें /v1/agents/sessions* शामिल हैं), /v1/mcp-connections*, /v1/secrets*, और /v1/skills* key को किसी भी header में स्वीकार करते हैं:

bash
curl https://api.sandbase.ai/v1/agents \
  -H "X-API-Key: $SANDBASE_API_KEY"
  • यदि Authorization: Bearer और X-API-Key दोनों भेजे जाते हैं, तो उनमें समान key होनी चाहिए; अलग-अलग मान 401 unauthorized लौटाते हैं। किसी भी header को दोहराने पर भी 401 लौटता है।
  • OpenAI-Beta वैकल्पिक है। यदि मौजूद हो, तो यह agents=v1 होना चाहिए।
  • read requests के लिए agents.read permission चाहिए और writes के लिए agents.write। मानक Console-created keys में दोनों होते हैं। SandBase-issued scoped keys, जैसे CLI Login keys, 403 insufficient_scope लौटाते हैं।
  • 402 spending_limit_exceeded का अर्थ है कि key की spending limit या organization balance समाप्त हो गया है।
  • विफलताएँ नीचे दिखाए गए flat {"error": "…"} form के बजाय Agents error envelope का उपयोग करती हैं।

API key format ​

नई Console-created API keys का format यह है:

sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Componentविवरण
sk-मानक "secret key" prefix
xxxx...32 random bytes से उत्पन्न 64 hexadecimal characters

Legacy sk-sb-... keys उनके expire होने या revoke होने तक उपयोग योग्य रहती हैं। Clients को keys को opaque strings की तरह मानना चाहिए, न कि उनके prefix या length के आधार पर किसी credential को अस्वीकार करना चाहिए।

WARNING

अपनी API key को कभी भी client-side code, public repositories, या logs में उजागर न करें। इसे password की तरह मानें।

API keys बनाएं ​

Console के माध्यम से ​

  1. SandBase Console में लॉग इन करें
  2. Developer → API Keys खोलें
  3. New key पर क्लिक करें
  4. key को एक वर्णनात्मक नाम दें (उदा., "Production Backend", "Development")
  5. key को तुरंत कॉपी करें — यह दोबारा नहीं दिखाई जाएगी

Key Properties ​

Propertyविवरण
Nameपहचान के लिए मानव-पठनीय label
Organizationवह org जिससे यह key संबंधित है
Enabledक्या key सक्रिय है
Spending Limitवैकल्पिक per-key spending cap
Expires Atवैकल्पिक expiration date
Created Atkey कब बनाई गई थी

मानक Console-created keys दस्तावेज़ित public API के लिए organization-level access का उपयोग करती हैं। SandBase-issued credentials, जैसे CLI Login keys, restricted scope रख सकती हैं। Console मानक keys के लिए user-selected scopes प्रदर्शित नहीं करता।

Key lifecycle ​

Rotation ​

key को rotate करने के लिए:

  1. Console में एक नई key बनाएं
  2. अपने application को नई key उपयोग करने के लिए अपडेट करें
  3. सत्यापित करें कि नई key production में काम करती है
  4. पुरानी key revoke करें

TIP

डाउनटाइम से बचने के लिए पुरानी key revoke करने से पहले हमेशा नई key बनाएं।

Revocation ​

Revoked keys नए requests को authenticate नहीं कर सकतीं। API निम्न संदेश के साथ 401 Unauthorized लौटाती है:

json
{"error":"API key has been revoked"}

Expiration ​

Keys के लिए वैकल्पिक expiration date हो सकती है। Expired keys निम्न संदेश के साथ 401 Unauthorized लौटाती हैं:

json
{"error":"API key has expired"}

Endpoint Authentication Requirements ​

EndpointAuth Methodविवरण
POST /v1/chat/completionsAPI Key (Bearer)Chat Completions
POST /v1/responsesAPI Key (Bearer)OpenAI-compatible Responses API
POST /v1/messagesAPI Key (Bearer or x-api-key)Anthropic Messages
/v1beta/models/*API Key (x-goog-api-key, Bearer, or query key)Gemini GenerateContent
/v1beta/interactions*API Key (x-goog-api-key, Bearer, or query key)Gemini Interactions
/v1/agents*, /v1/mcp-connections*, /v1/secrets*, /v1/skills*API Key (Bearer or X-API-Key)Agents platform resources

SandBase Console एक अलग browser authentication flow का उपयोग करता है। इसके internal requests समर्थित public endpoints नहीं हैं और integrations द्वारा उपयोग नहीं किए जाने चाहिए।

Organization Isolation ​

API keys organization के लिए scoped होती हैं। जब आप किसी key से authenticate करते हैं:

  • आप केवल अपनी organization से संबंधित resources तक पहुँच सकते हैं
  • usage और billing organization के अनुसार tracked होते हैं

Error Responses ​

HTTP StatusMessageCause
401missing API key in Authorization headerकोई key प्रदान नहीं की गई
401invalid API keyKey database में नहीं मिली
401API key has been revokedKey disabled थी
401API key has expiredKey expiration date पार कर चुकी है
402 or protocol-specific 403API key spending limit exceededKey-level spending limit पहुँच गई; endpoint के documented error contract की जाँच करें
403API key is not authorized for this endpointScoped key को उसके scope के बाहर के endpoint पर उपयोग किया गया

ये messages flat {"error":"<message>"} body में आते हैं, सिवाय 403 scope errors के। model और account endpoints पर ये {"error":{"code":"insufficient_scope","message":"API key is not authorized for this endpoint","request_id":"..."}} का उपयोग करते हैं; Agents platform resources पर ये code insufficient_scope के साथ Agents error envelope का उपयोग करते हैं।

सुरक्षा सर्वोत्तम प्रथाएँ ​

करें ​

  • Keys को environment variables में store करें — Keys को source code में कभी hardcode न करें
  • प्रत्येक environment के लिए अलग keys का उपयोग करें — dev, staging, production के लिए अलग keys
  • Expiration dates सेट करें — अपनी security policy के लिए उपयुक्त rotation interval चुनें
  • Usage monitor करें — अप्रत्याशित activity के लिए Console जांचें
  • केवल उन workloads के लिए standard keys का उपयोग करें जिन्हें public API access की आवश्यकता है — scoped CLI Login credentials को उनके managed flow में रखें

न करें ​

  • Keys को version control में commit न करें — .env को .gitignore में जोड़ें
  • एक key को असंबंधित applications के बीच साझा न करें — अलग keys rotation और incident response को अधिक सुरक्षित बनाती हैं
  • Client-side code में keys expose न करें — हमेशा अपने backend के माध्यम से proxy करें
  • API keys को log न करें — application logs में keys redact करें

Environment Variable Example ​

bash
SANDBASE_API_KEY=sk-your-api-key
python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SANDBASE_API_KEY"],
    base_url="https://api.sandbase.ai/v1"
)
javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.SANDBASE_API_KEY,
  baseURL: 'https://api.sandbase.ai/v1',
});

Key के अनुसार Rate Limiting ​

Request limits organization के account level के अनुसार सेट किए जाते हैं और उसके सभी API keys द्वारा साझा किए जाते हैं, इसलिए अधिक keys बनाने से वे नहीं बढ़ते। API remaining-quota headers नहीं भेजता।

Limits और 429 responses को handle करने के विवरण के लिए Rate Limiting देखें।