SUB&SUB · Docs

API Reference

SUB&SUB https://api.subnsub.com/v1 पर एक multi-provider relay expose करता है। OpenAI clients /v1/chat/completions पर hit करते हैं; Anthropic clients /v1/messages पर hit करते हैं। एक ही sk-cf-... key दोनों को route करती है — request body में model चुनें और relay upstream चुन लेता है।

Quick start

तीन चीज़ें जो आपको चाहिए:

  1. Base URL: https://api.subnsub.com/v1 (OpenAI clients) या https://api.subnsub.com (Anthropic clients — SDK खुद /v1/messages append कर लेता है)
  2. API key: console से जारी की गई sk-cf-...
  3. Model: 21 verified models में से एक — जैसे gpt-5.4-mini या claude-haiku-4.5

Authentication

हर request में एक Authorization: Bearer sk-cf-... header होना ज़रूरी है। Keys console से जारी की जाती हैं और SHA-256 hashes के रूप में store होती हैं — creation screen छोड़ते ही plaintext हमेशा के लिए चला जाता है, इसलिए उसे तुरंत save करें।

Tip हर integration (chatbot, IDE plugin, batch job) के लिए एक अलग key generate करें। Console में leaked key को revoke करना कुछ ही seconds में लागू हो जाता है।

Endpoints

POST /v1/chat/completions

POST/v1/chat/completions

एक chat completion request भेजें। Request का shape OpenAI Chat Completions API से मेल खाता है — OpenAI SDKs बिना बदलाव के काम करते हैं।

ParameterTypeविवरण
modelstringverified model IDs में से एक।
messagesarrayConversation history। हर item: {role, content} जहाँ rolesystem / user / assistant
streambooleanअगर true है, तो response SSE chunks के रूप में भेजा जाता है। देखें Streaming
stream_optionsobjectOptional। Relay हमेशा upstream {include_usage: true} force करता है ताकि अंतिम chunk में token-usage block आए — इसे override करने का कोई असर नहीं होता।
max_tokensintegerCompletion की length को cap करता है। Default model की maximum होती है।
temperaturenumber0 – 2। ज़्यादा = ज़्यादा random।

POST /v1/messages

POST/v1/messages

claude-* models के लिए Anthropic-native endpoint — Anthropic SDK (anthropic-sdk-python, @anthropic-ai/sdk, claude-code) इस path के विरुद्ध बिना बदलाव के काम करता है। अपना base URL https://api.subnsub.com पर point करें और x-api-key header के ज़रिए authenticate करें (अगर आपका client पसंद करे तो Authorization-Bearer form भी काम करता है)।

ParameterTypeविवरण
modelstringएक claude-* model ID (देखें उपलब्ध models)। यहाँ कोई OpenAI model पास करने पर 400 invalid_request_error लौटता है।
max_tokensintegerAnthropic के लिए आवश्यक — assistant reply की length को cap करता है।
messagesarrayConversation history, Anthropic shape: {role, content} जहाँ roleuser / assistant
streambooleanअगर true है, तो standard Anthropic SSE event sequence लौटता है: message_start, content_block_delta, message_delta, message_stop
thinkingobjectज्यों का त्यों forward किया जाता है। Extended thinking enable करने के लिए किसी -thinking model variant के साथ pair करें।
cache_controlobjectPrompt-caching समर्थित है। Cache-write tokens tier के input rate के 1.25× पर और cache-read tokens 0.10× पर bill होते हैं।
ध्यान दें हर Claude request upstream एक ~4100-token Kiro system prompt ले जाती है — यह model के tier rate पर सामान्य input tokens के रूप में bill होता है। जो short prompts अन्यथा सस्ते होते, उन पर भी यह floor लगता है।

GET /v1/models

GET/v1/models

वे models list करता है जिन्हें आप वास्तव में call कर सकते हैं। Relay sub2api से OpenAI और Anthropic catalogues को merge करता है और उन 21 models तक filter करता है जिन्हें हमने current account pool के विरुद्ध end-to-end-test किया है — phantom IDs जो routing time पर 503 देते हैं, या first token पर upstream-400 देते हैं, छिपा दिए जाते हैं। अगर हर configured upstream unreachable हो, तो endpoint एक भ्रामक खाली list के बजाय 502 models_unreachable लौटाता है।

# sample response (truncated)
{
  "object": "list",
  "data": [
    { "id": "gpt-5.4-mini",      "type": "model", ... },
    { "id": "gpt-5.4",           "type": "model", ... },
    { "id": "claude-sonnet-4.5", "type": "model", ... },
    { "id": "claude-haiku-4.5",  "type": "model", ... },
    ...
  ]
}

उपलब्ध models

दो upstream families। 7 OpenAI models shared ChatGPT-tier accounts पर route होते हैं; 14 Claude models एक Kiro reverse proxy के ज़रिए AWS CodeWhisperer पर route होते हैं। Per-token rates tier पर निर्भर करते हैं (देखें Pricing) — एक ही key दोनों के लिए काम करती है।

OpenAI

Model IDFamilyTierNotes
gpt-5.4-mini GPT-5.4Mini तेज़ & सस्ता। Chat & coding के लिए अनुशंसित default।
gpt-5.3-codex Codex Mini Coding-tuned 5.3। mini के समान price।
gpt-5.2 GPT-5.2StandardStable 5.2।
gpt-5.2-chat-latestGPT-5.2Standardनवीनतम 5.2 chat tune को auto-track करता है (फ़िलहाल upstream gpt-5.2 पर map होता है)।
gpt-5.4 GPT-5.4StandardFull-size GPT-5.4 — धीमा, अधिक मज़बूत reasoning।
gpt-5.4-2026-03-05GPT-5.4Standardgpt-5.4 का date-stamped snapshot।
gpt-5.5 GPT-5.5Premium नया flagship।

Anthropic

Model IDFamilyTierNotes
claude-haiku-4.5 Haiku 4.5 Mini सबसे छोटा Claude — gpt-5.4-mini के समान per-token rate।
claude-haiku-4.5-thinking Haiku 4.5 Mini haiku-4.5 का extended-thinking variant। thinking request field के साथ pair करें।
claude-sonnet-4.5 Sonnet 4.5 StandardMid-tier Claude — gpt-5.4 के समान per-token rate।
claude-sonnet-4.5-thinking Sonnet 4.5 Standardsonnet-4.5 का extended-thinking variant।
claude-sonnet-4.6 Sonnet 4.6 Standardनया Sonnet tune — Standard tier, sonnet-4.5 के समान rate।
claude-sonnet-4.6-thinking Sonnet 4.6 Standardsonnet-4.6 का extended-thinking variant।
claude-opus-4.5 Opus 4.5 Ultra Frontier Claude। Anthropic के list price पर bill होता है — कोई margin नहीं (देखें Pricing)।
claude-opus-4.5-thinking Opus 4.5 Ultra opus-4.5 का extended-thinking variant (adaptive thinking)।
claude-opus-4.6 Opus 4.6 Ultra नया Opus tune।
claude-opus-4.6-thinking Opus 4.6 Ultra opus-4.6 का extended-thinking variant।
claude-opus-4.7 Opus 4.7 Ultra पिछला Opus snapshot।
claude-opus-4.7-thinking Opus 4.7 Ultra opus-4.7 का extended-thinking variant।
claude-opus-4.8 Opus 4.8 Ultra नवीनतम Opus snapshot।
claude-opus-4.8-thinking Opus 4.8 Ultra opus-4.8 का extended-thinking variant।
ध्यान दें हर Claude request input के रूप में एक ~4100-token Kiro system prompt ले जाती है — यह आपके token bill में शामिल है। Anthropic prompt-caching समर्थित है: cache writes tier के input rate के 1.25× पर और reads 0.10× पर bill होते हैं (देखें Pricing)।
उपलब्ध नहीं Pro variants (gpt-5.2-pro, gpt-5.2-pro-2025-12-11), gpt-4o, gpt-4o-mini, gpt-5, gpt-5-mini, image / audio / realtime variants, claude-haiku-4-6, और dated upstream IDs (जैसे claude-sonnet-4-5-20250929)। इन्हें call करने पर 400 model_not_available लौटता है। Pro models menu से बाहर हैं क्योंकि pool में underlying social-tier accounts अपने छोटे quotas को कुछ ही requests में ख़त्म कर देंगे।

Reasoning effort

ऊपर का हर OpenAI model एक reasoning model है — backend visible output emit करने से पहले अधिक या कम "thinking" tokens खर्च कर सकता है। Budget को control करने के लिए OpenAI /v1/chat/completions request body पर reasoning_effort set करें। Claude के लिए, Anthropic-native thinking request field का उपयोग करें (या कोई -thinking model variant चुनें) — देखें /v1/messages section। OpenAI models समान पाँच effort values स्वीकार करते हैं:

Valueव्यवहार
none कोई thinking नहीं — सीधे answer तक। सबसे सस्ता और सबसे तेज़।
low एक छोटा reasoning pass।
medium अगर आप field पास नहीं करते तो default। संतुलित।
high गहरा reasoning। non-trivial coding / multi-step problems के लिए अनुशंसित।
xhigh अधिकतम effort। सबसे धीमा और सबसे महँगा; इसे कठिन analysis के लिए रखें जहाँ आपको वास्तव में इसकी ज़रूरत हो।
# Two equivalent forms — pick whichever your SDK supports
{
  "model": "gpt-5.4-mini",
  "reasoning_effort": "high",
  "messages": [ ... ]
}

{
  "model": "gpt-5.5",
  "reasoning": { "effort": "xhigh" },
  "messages": [ ... ]
}
लागत Thinking tokens billing के लिए output tokens के रूप में गिने जाते हैं — ज़्यादा effort = ज़्यादा output tokens = उसी prompt पर बड़ा bill। Per-token rate नहीं बदलता।
ध्यान दें OpenAI protocol 'minimal' भी परिभाषित करता है, लेकिन हमारे pool के models इसे reject करते हैं: "'minimal' is not supported with this model"। ऊपर की पाँच values पर ही टिके रहें।

Streaming

Server-Sent Events पाने के लिए "stream": true set करें। अंतिम chunk में एक usage block होता है (हम upstream stream_options.include_usage force करते हैं ताकि token counts हमेशा emit हों), फिर एक literal data: [DONE] stream को बंद कर देता है।

# Streaming format (line by line)
data: {"id":"resp_...","choices":[{"delta":{"content":"Hi"}}]}

data: {"id":"resp_...","choices":[{"delta":{"content":"!"}}]}

data: {"id":"resp_...","choices":[],"usage":{"prompt_tokens":18,"completion_tokens":11,"total_tokens":29}}

data: [DONE]

endpoint द्वारा समर्थित किसी भी model ID में :online append करें और relay model को forward करने से पहले एक web search चलाएगा, results को conversation के आगे prepend करते हुए ताकि answer ताज़े data पर आधारित हो। यह suffix /v1/chat/completions और /v1/messages पर काम करता है (बाद वाले को फिर भी एक claude-* base चाहिए); कोई search-specific request fields ज़रूरी नहीं।

# Same call as before — just :online on the model
curl https://api.subnsub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-cf-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini:online",
    "messages": [
      {"role": "user", "content": "What did Anthropic ship this week?"}
    ]
  }'

यह कैसे काम करता है: relay :online हटाता है, सबसे हालिया user message को query के रूप में लेता है (400 characters पर capped), उपलब्ध होने पर extracted page text के साथ अधिकतम 3 results के लिए Tavily को call करता है, साथ ही एक optional Tavily-generated summary, फिर उन्हें request upstream भेजने से पहले उसी user turn के आगे एक स्पष्ट रूप से सीमांकित <search_results> block के रूप में prepend करता है। Search call का 8-second timeout होता है। Results जानबूझकर user role में inject किए जाते हैं — कभी system prompt में नहीं — ताकि untrusted snippets को system-priority instructions तक न बढ़ाया जा सके।

<search_results> block इस तरह दिखता है। इसके पहले एक one-line instruction होता है जो model को बताता है कि block को untrusted external data मानें और numbered items को inline cite करें:

<search_results query="What did Anthropic ship this week?" retrieved="2026-05-21">
Summary: <short LLM-generated synthesis of the result set>

[1] Anthropic launches Opus 4.8
URL: https://www.anthropic.com/news/opus-4-8
<extracted page text, or short snippet if extraction failed — up to ~2000 chars>

[2] ...
</search_results>
व्यवहारविवरण
लागतआज कोई surcharge नहीं — आप model के सामान्य per-token rate का भुगतान करते हैं; relay search call को absorb कर लेता है। Inject किया गया <search_results> block input tokens के रूप में गिना जाता है, इसलिए :online के बिना उसी सवाल की तुलना में ज़्यादा prompt-token bill की उम्मीद रखें।
Failure modeSoft। अगर Tavily time out या error करता है, तो request बिना search context के model तक जारी रहती है (आपको फिर भी answer मिलता है, बस ungrounded)। एकमात्र hard failure 503 search_unavailable है जब relay पर search बिल्कुल भी configured न हो।
count_tokens/v1/messages/count_tokens suffix हटाता है लेकिन Tavily को कभी call नहीं करता — count आपके original prompt को दर्शाता है, augmented को नहीं।
Multi-turnकेवल अंतिम user turn को query & augment किया जाता है; पहले के turns अछूते रहते हैं। फिर से search करने के लिए, model पर :online रखते हुए एक नया user message भेजें।

:online का उपयोग कब करें

Relay हर request पर एक ही Tavily call करता है और results inject करता है — यह कोई agentic search loop नहीं है। Model जो देखता है उसके आधार पर फिर से search करने का फ़ैसला नहीं करता, जैसा Perplexity Sonar या ChatGPT browse tool करते हैं। इस सीमा को ध्यान में रखकर योजना बनाएँ:

उपयुक्तअनुपयुक्त
समय-संवेदनशील तथ्य (news, prices, version numbers, release dates)Private या pasted code जो public web पर नहीं है — grounding के बिना prompt noise जोड़ता है
किसी official doc या announcement को खोजनाMath, reasoning, translation, creative writing — ground करने के लिए कुछ नहीं
कुछ भी जिसे आप अन्यथा Googling करके verify करतेTraining data में पहले से मौजूद stable knowledge ("binary tree क्या है")

अंतिम user message को एक standalone search query के रूप में लिखें। Search आपके सबसे हालिया user turn के literal text के विरुद्ध चलती है (400 chars पर capped), इसलिए "और नवीनतम version के बारे में क्या?" जैसे conversational follow-ups बिना context के बेकार queries बन जाते हैं। Multi-turn chat में, जब आप :online जोड़ें तो topic को दोबारा बताएँ — जैसे "the latest one" के बजाय "latest version of the Anthropic Python SDK"

जिन सवालों में multi-step synthesis चाहिए (compare-and-contrast, deep research), उन्हें कई turns में बाँटें और हर एक में :online जोड़ें। Model हर turn के ताज़े results पढ़ेगा; आप अगली query को manually steer करते हैं। ध्यान दें कि inject किया गया <search_results> block केवल upstream भेजा जाता है — यह आपके client को वापस echo नहीं होता और अगली request में preserve नहीं होता, इसलिए अगर कोई बाद वाला turn पहले के sources के विवरणों पर निर्भर हो, तो model से कहें कि वह उन्हें अपने visible reply में summarise करे। One-shot research mode समर्थित नहीं है।

Tip high reasoning effort (reasoning_effort: "high") के साथ combine करें ताकि model पहले result पर निर्भर रहने के बजाय वास्तव में लौटाए गए sources को तौले। Inject किया गया instruction model से numbered sources को inline [1], [2] के रूप में cite करने को कहता है, इसलिए output में आमतौर पर ऐसे citations होंगे — हालाँकि model उस format के लिए सख़्ती से बाध्य नहीं है।

Errors

Envelope इस पर निर्भर करता है कि आपने कौन-सा endpoint call किया — relay errors को उस protocol में लौटाता है जो caller के SDK से मेल खाता है, और upstream errors ज्यों के त्यों pass through किए जाते हैं।

OpenAI paths (/v1/chat/completions, /v1/responses, /v1/models) — OpenAI envelope:

{ "error": { "message": "...", "type": "...", "code": "..." } }

Anthropic paths (/v1/messages, /v1/messages/count_tokens) — Anthropic envelope:

{ "type": "error", "error": { "type": "...", "message": "..." } }

Anthropic envelope एक अलग shape का उपयोग करता है — कोई code field नहीं, और discriminator type: "error" top level पर होता है (inner error.type category देता है, जैसे authentication_error, invalid_request_error, permission_error, api_error)। Anthropic SDKs पहले से इस shape को parse करते हैं; सादे OpenAI SDK error handlers नहीं करते, इसलिए /v1/messages को किसी Anthropic SDK के साथ call करें (या raw HTTP करें)।

Status codes दोनों protocols में canonical HTTP वाले ही हैं:

StatusOpenAI code / Anthropic error.typeअर्थ
401invalid_api_key / authentication_errorगायब या अज्ञात sk-cf-... key।
402insufficient_balance / permission_errorAccount balance negative है। console billing tab में top up करें।
403key_revoked / permission_errorKey revoke कर दी गई थी।
400model_not_available / invalid_request_errorआपने जो model भेजा वह verified catalogue में नहीं है, या endpoint के लिए ग़लत है (जैसे /v1/messages पर एक OpenAI model) — देखें उपलब्ध models
503फ़िलहाल कोई upstream account request को serve नहीं कर रहा — आमतौर पर एक pool-wide rate-limit window, न कि कोई config issue।
503search_unavailable / api_errorआपने :online उपयोग किया लेकिन इस relay पर web search configured नहीं है। देखें Web search
502upstream_unreachable / api_errorRelay backend तक नहीं पहुँच सका। एक छोटे backoff के बाद retry करें।

Pricing और billing

Pay-as-you-go, microdollars में per token bill होता है (1 micro = $0.000001 = एक cent का 1/10,000) ताकि sub-cent requests सटीक रूप से track हों। Rates per 1M tokens हैं, tier के अनुसार — कौन-सा model किस tier पर map होता है, इसके लिए model table देखें।

TierModelsInput / 1MOutput / 1M
Mini gpt-5.4-mini, gpt-5.3-codex, claude-haiku-4.5, claude-haiku-4.5-thinking $0.20$1.60
Standardgpt-5.2, gpt-5.2-chat-latest, gpt-5.4, gpt-5.4-2026-03-05, claude-sonnet-4.5, claude-sonnet-4.5-thinking, claude-sonnet-4.6, claude-sonnet-4.6-thinking$0.75$6.00
Premium gpt-5.5 $1.10$8.80
Ultra claude-opus-4.5, claude-opus-4.5-thinking, claude-opus-4.6, claude-opus-4.6-thinking, claude-opus-4.7, claude-opus-4.7-thinking, claude-opus-4.8, claude-opus-4.8-thinking$5.00$25.00

Ultra-tier rates Anthropic के published Opus list price से मेल खाते हैं — सीधा pass-through, कोई margin नहीं। बाक़ी tiers pooled subscription backing की बदौलत अपने upstream rates से नीचे चलते हैं।

Reasoning tokens (जब आप OpenAI पर reasoning_effort set करते हैं, या किसी Claude -thinking variant का उपयोग करते हैं) model के tier rate पर output tokens के रूप में गिने जाते हैं — high effort के लिए कोई अलग surcharge नहीं है, लेकिन एक deep-thinking request आसानी से no-effort वाली request से 10–50× अधिक output tokens emit कर सकती है, इसलिए dollar bill उसी के साथ scale होता है।

Anthropic prompt-caching एक अलग line item के रूप में bill होती है: cache writes tier के input rate के 1.25× पर और cache reads 0.10× पर। तो एक haiku-4.5 cache hit की लागत 0.20 × 0.10 = $0.02 per 1M tokens होती है, और एक sonnet-4.5 cache hit की लागत 0.75 × 0.10 = $0.075 per 1M tokens होती है। Cache columns हर settle row पर record होते हैं ताकि console breakdown दिखा सके।

Balance real time में काटा जाता है जैसे ही हर request लौटती है — streaming requests के लिए, settlement [DONE] chunk आने के बाद चलता है। अपना live balance और per-request settlements /console#billing पर देखें।

Top-up Console Stripe Checkout को support करता है — card, Link, Alipay, WeChat Pay (जो भी Stripe account पर enabled हो)। Credits कभी expire नहीं होते।

Rate limits

आज कोई per-key rate limits नहीं हैं। Upstream account pool concurrency & OpenAI server-side throttling लागू होते हैं; अगर आप उनसे टकराते हैं, तो relay एक retry-after header के साथ 429 लौटाता है। Per-key RPM / TPM limits post-MVP आएँगी।