प्रमाणीकरण
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 शामिल करें:
Authorization: Bearer sk-your-api-keyयह OpenAI-compatible SDKs द्वारा उपयोग की जाने वाली मानक विधि है।
Anthropic Messages: x-api-key header
x-api-key header में key शामिल करें:
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 में स्वीकार करते हैं:
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.readpermission चाहिए और 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 के माध्यम से
- SandBase Console में लॉग इन करें
- Developer → API Keys खोलें
- New key पर क्लिक करें
- key को एक वर्णनात्मक नाम दें (उदा., "Production Backend", "Development")
- key को तुरंत कॉपी करें — यह दोबारा नहीं दिखाई जाएगी
Key Properties
| Property | विवरण |
|---|---|
| Name | पहचान के लिए मानव-पठनीय label |
| Organization | वह org जिससे यह key संबंधित है |
| Enabled | क्या key सक्रिय है |
| Spending Limit | वैकल्पिक per-key spending cap |
| Expires At | वैकल्पिक expiration date |
| Created At | key कब बनाई गई थी |
मानक 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 करने के लिए:
- Console में एक नई key बनाएं
- अपने application को नई key उपयोग करने के लिए अपडेट करें
- सत्यापित करें कि नई key production में काम करती है
- पुरानी key revoke करें
TIP
डाउनटाइम से बचने के लिए पुरानी key revoke करने से पहले हमेशा नई key बनाएं।
Revocation
Revoked keys नए requests को authenticate नहीं कर सकतीं। API निम्न संदेश के साथ 401 Unauthorized लौटाती है:
{"error":"API key has been revoked"}Expiration
Keys के लिए वैकल्पिक expiration date हो सकती है। Expired keys निम्न संदेश के साथ 401 Unauthorized लौटाती हैं:
{"error":"API key has expired"}Endpoint Authentication Requirements
| Endpoint | Auth Method | विवरण |
|---|---|---|
POST /v1/chat/completions | API Key (Bearer) | Chat Completions |
POST /v1/responses | API Key (Bearer) | OpenAI-compatible Responses API |
POST /v1/messages | API 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 Status | Message | Cause |
|---|---|---|
| 401 | missing API key in Authorization header | कोई key प्रदान नहीं की गई |
| 401 | invalid API key | Key database में नहीं मिली |
| 401 | API key has been revoked | Key disabled थी |
| 401 | API key has expired | Key expiration date पार कर चुकी है |
| 402 or protocol-specific 403 | API key spending limit exceeded | Key-level spending limit पहुँच गई; endpoint के documented error contract की जाँच करें |
| 403 | API key is not authorized for this endpoint | Scoped 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
SANDBASE_API_KEY=sk-your-api-keyimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["SANDBASE_API_KEY"],
base_url="https://api.sandbase.ai/v1"
)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 देखें।