चैट पूर्णता
एक एपीआई से 100+ मॉडलों में चैट प्रतिक्रियाएँ उत्पन्न करें। ड्रॉप-इन OpenAI चैट कंप्लीशन्स, Anthropic मैसेज और Anthropic रिस्पॉन्स के साथ संगत है।
Airforce एक ही मॉडल सेट पर OpenAI Chat Completions और Anthropic Messages दोनों wire formats में बात करता है। आप जो भी SDK पहले से इस्तेमाल करते हैं उसे चुनें और सिर्फ base URL बदलें — गैर-Claude मॉडल किसी भी surface के पीछे transparently forward कर दिए जाते हैं।
यह पेज authentication, दोनों surfaces के request और response shapes, streaming, tool calling, vision, reasoning, और prompt caching को कवर करता है। यहाँ नए हैं? नीचे दिए बेसिक उदाहरण से शुरू करें, एक call काम करवाएँ, फिर वह चलने पर streaming, tools या caching जोड़ते जाएँ।
प्रमाणीकरण
प्रत्येक अनुरोध के लिए बियरर टोकन (आपकी Airforce एपीआई कुंजी) की आवश्यकता होती है। Anthropic x-api-key हेडर भी स्वीकार किया जाता है /v1/messages एसडीके अनुकूलता के लिए.
Authorization: Bearer sk-air-YOUR_API_KEY
# alt for /v1/messages:
x-api-key: sk-air-YOUR_API_KEYPOST /v1/chat/completions
OpenAI-संगत चैट पूर्णताएँ। अधिकारी के साथ काम करता है openai ओवरराइड करके SDK base_url को https://api.airforce/v1.
https://api.airforce/v1/chat/completionsनिकाय से अनुरोध करें
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Required | मॉडल आईडी. उपलब्ध आईडी खोजने के लिए GET /v1/models का उपयोग करें। |
| messages | array | Required | बातचीत का इतिहास। प्रत्येक प्रविष्टि में { role: "system" | "user" | "assistant" | "tool", content } होता है। कंटेंट एक string या कंटेंट ब्लॉकों की एक array होती है (विज़न, नीचे देखें)। |
| max_tokens | integer | Optional | उत्पन्न करने के लिए टोकन की अधिकतम संख्या. मॉडल के max_output_tokens पर कैप किया गया। |
| temperature | float | Optional | नमूनाकरण तापमान, 0-2. निचला अधिक नियतिवादी है। डिफ़ॉल्ट अपस्ट्रीम प्रदाता पर निर्भर करता है। |
| top_p | float | Optional | नाभिक नमूनाकरण. या तो तापमान या टॉप_पी का उपयोग करें, दोनों का नहीं। |
| stream | boolean | Optional | सत्य होने पर, प्रतिक्रिया सर्वर-भेजे गए ईवेंट की एक स्ट्रीम है। नीचे "स्ट्रीमिंग" देखें। |
| models | array | Optional | Fallback models (max 3), e.g. ["deepseek-v3.2", "gpt-4o-mini"]. If every channel of the primary model fails, each candidate is tried in order. You are billed for — and response.model reports — the model that actually answered. Unknown or plan-gated candidates are skipped. With the OpenAI SDK pass it via extra_body. |
| transforms | array | Optional | Prompt transforms. Supported: ["middle-out"] — when the conversation overflows the model's context window, whole messages are dropped from the middle (system prompts, the first message and the most recent turns are kept), so long roleplay or agent histories keep working instead of erroring. Opt-in; off by default. |
| stream_options | object | Optional | { include_usage: boolean }. Usage हमेशा अंतिम स्ट्रीमिंग chunk में शामिल होता है; यह फ़ील्ड OpenAI संगतता के लिए स्वीकार किया जाता है लेकिन इसे बंद नहीं किया जा सकता। |
| stop | string | array | Optional | 4 स्टॉप सीक्वेंस तक। उत्पादन होते ही उत्पादन रुक जाता है। |
| tools | array | Optional | फ़ंक्शन परिभाषाओं को मॉडल कॉल कर सकता है। नीचे "टूल कॉलिंग" देखें। |
| tool_choice | string | object | Optional | किसी विशिष्ट कॉल को बाध्य करने के लिए "auto" (डिफ़ॉल्ट), "none", या { type: "function", function: { name } }। |
| response_format | object | Optional | { type: "json_object" } मॉडल को वैध JSON उत्सर्जित करने के लिए बाध्य करता है। जो मॉडल इसका समर्थन नहीं करते, उन पर अनदेखा किया जाता है। |
| reasoning_effort | string | Optional | OpenAI o1/o3-शैली तर्क गहराई: "कम" | "मध्यम" | "उच्च"। "तर्क और सोच" देखें। |
| thinking | string | object | Optional | क्रॉस-प्रोवाइडर थिंकिंग स्विच। "on" | "off" | "auto", या Anthropic-शैली { type: "enabled", budget_tokens: N }। "Reasoning & thinking" देखें। |
| thinking_budget | integer | Optional | मॉडल के रीजनिंग ट्रेस के लिए टोकन कैप (जब प्रदाता किसी को उजागर करता है)। |
| ignore_defaults | boolean | Optional | इस अनुरोध के लिए उपयोगकर्ता के सहेजे गए प्रति-मॉडल डिफ़ॉल्ट पैरामीटर (डैशबोर्ड में कॉन्फ़िगर) को छोड़ दें। |
मूल उदाहरण
curl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"max_tokens": 200,
"temperature": 0.7
}'प्रतिक्रिया स्वरूप
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | string | Optional | स्थिर पूर्णता आईडी, उदा. "चैटसीएमपीएल-एबीसी123"। |
| object | string | Optional | गैर-स्ट्रीम के लिए "chat.completion", स्ट्रीम किए गए के लिए "chat.completion.chunk"। |
| created | integer | Optional | यूनिक्स टाइमस्टैम्प (सेकंड)। |
| model | string | Optional | अनुरोधित मॉडल आईडी की प्रतिध्वनि। |
| choices | array | Optional | पूर्णता उम्मीदवारों की array: [{ index, message: { role, content, tool_calls? }, finish_reason }]। |
| choices[].finish_reason | string | Optional | "रुको" | "लंबाई" | "टूल_कॉल्स" | "सामग्री_फ़िल्टर"। |
| usage | object | Optional | { prompt_tokens, completion_tokens, total_tokens, completion_tokens_details?, prompt_tokens_details?, cache_creation_input_tokens?, cache_creation? }. completion_tokens_details.reasoning_tokens तब सेट होता है जब मॉडल ने रीज़निंग ट्रेस उत्पन्न किया। कैश फ़ील्ड्स तब दिखाई देते हैं जब अपस्ट्रीम ने प्रॉम्प्ट-कैशिंग जानकारी लौटाई: prompt_tokens_details.cached_tokens कैश रीड्स (OpenAI मानक) की रिपोर्ट करता है, cache_creation_input_tokens राइट्स को एकत्र करता है, और cache_creation.ephemeral_5m_input_tokens / ephemeral_1h_input_tokens TTL विभाजन देते हैं। |
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1710000000,
"model": "gpt-5.1-chat",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 8,
"total_tokens": 28
}
}तर्क और सोच
विस्तारित तर्क का समर्थन करने वाले मॉडल नियमित आउटपुट के साथ-साथ एक सोच का पता लगाते हैं। Airforce तीन अलग-अलग अपस्ट्रीम सम्मेलनों को विहित मापदंडों के एक सेट में सामान्यीकृत करता है जो हर जगह काम करते हैं।
जाँच करना supports_reasoning: true में एक मॉडल पर GET /v1/models यह जानने के लिए कि कौन सी आईडी इन मापदंडों को स्वीकार करती हैं।
तर्क समर्थन वाले मॉडल
…· liveविहित पैरामीटर
| Parameter | Type | Required | Description |
|---|---|---|---|
| reasoning_effort | string | Optional | "कम" | "मध्यम" | "उच्च"। OpenAI o1/o3, GPT-5 रीज़निंग मॉडल, और कोई भी राउटर जो उन पर मैप करता है। |
| thinking | string | object | Optional | त्वरित टॉगल के लिए "on" | "off" | "auto", या Anthropic-नेटिव शैली के लिए { type: "enabled", budget_tokens: N }। Claude विस्तारित थिंकिंग, Gemini थिंकिंग और DeepSeek रीज़निंग से मैप होता है। |
| thinking_budget | integer | Optional | दृश्यमान आउटपुट उत्सर्जित करने से पहले मॉडल अधिकतम टोकन तर्क पर खर्च कर सकता है। दर्पण बजट_टोकन। |
तर्क प्रयास (OpenAI-शैली)
curl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "o3-mini",
"messages": [{"role": "user", "content": "Prove the Pythagorean theorem."}],
"reasoning_effort": "high"
}'विस्तारित सोच (Anthropic-शैली)
curl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4.6",
"messages": [{"role": "user", "content": "Plan a 7-day Italy trip."}],
"thinking": {"type": "enabled", "budget_tokens": 4000}
}'तर्क का निशान स्वयं प्रकट होता है choices[0].message.reasoning (OpenAI आकार) या जैसे thinking में ब्लॉक करता है content (Anthropic आकृति)। रीज़निंग टोकन को बिल किया जाता है और रिपोर्ट किया जाता है usage.completion_tokens_details.reasoning_tokens.
वह completion_tokens_details.reasoning_tokens विवरण केवल तभी मौजूद होता है जब अपस्ट्रीम प्रोवाइडर इसे रिपोर्ट करता है। एक streamed रिस्पॉन्स पर ट्रेस प्रति chunk delta.reasoning_content पर आता है।
दृष्टि एवं छवि इनपुट
के साथ मॉडल supports_vision: true सामग्री ब्लॉक के रूप में एम्बेड की गई छवियों को स्वीकार करें। या तो एक सार्वजनिक यूआरएल या बेस64 डेटा यूआरएल काम करता है; आकार सीमाएँ अपस्ट्रीम मॉडल पर निर्भर करती हैं।
दृष्टि समर्थन वाले मॉडल
…· livecurl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1-chat",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}
]
}]
}'टूल कॉलिंग
के साथ मॉडल supports_tools: true आपके द्वारा परिभाषित फ़ंक्शंस को कॉल कर सकते हैं। मॉडल एक लौटाता है tool_calls सारणी; आप कॉल चलाएं, फिर परिणाम वापस भेजें tool संदेश।
टूल कॉलिंग समर्थन वाले मॉडल
…· liveअनुरोध
curl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1-chat",
"messages": [{"role": "user", "content": "What is the weather in Paris?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
}],
"tool_choice": "auto"
}'टूल कॉल के साथ प्रतिक्रिया
{
"id": "chatcmpl-abc123",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_1",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}]
},
"finish_reason": "tool_calls"
}]
}टूल परिणाम के साथ अनुवर्ती कार्रवाई करें
{
"model": "gpt-5.1-chat",
"messages": [
{"role": "user", "content": "What is the weather in Paris?"},
{
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_1",
"type": "function",
"function": {"name": "get_weather", "arguments": "{\"location\":\"Paris\"}"}
}]
},
{"role": "tool", "tool_call_id": "call_1", "content": "{\"temp_c\": 14, \"sky\": \"cloudy\"}"}
]
}Structured outputs
Set response_format to make the model return JSON. Two modes are supported:
{ "type": "json_object" }— the response is a single valid JSON value.{ "type": "json_schema", "json_schema": { "name", "schema", "strict" } }— the model is steered to produce JSON that matches your JSON Schema.
curl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1-chat",
"messages": [{"role": "user", "content": "Extract the city and country: I live in Paris, France."}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "location",
"schema": {
"type": "object",
"properties": { "city": {"type": "string"}, "country": {"type": "string"} },
"required": ["city", "country"]
}
}
}
}'Reliability: even when a model wraps its answer in prose or a markdown code fence, Airforce extracts the JSON payload so you always receive parseable content. If no valid JSON can be recovered, the original text is returned unchanged — so the guarantee never makes a response worse. This applies to non-streamed responses; streamed responses are passed through unchanged.
स्ट्रीमिंग
तय करना stream: true सर्वर-भेजे गए ईवेंट के रूप में आंशिक पूर्णताएँ प्राप्त करने के लिए। प्रत्येक घटना एक JSON खंड है जिसका आकार गैर-स्ट्रीम प्रतिक्रिया के समान है, सिवाय इसके message द्वारा प्रतिस्थापित किया जाता है delta. धारा समाप्त होती है data: [DONE].
curl https://api.airforce/v1/chat/completions \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1-chat",
"messages": [{"role": "user", "content": "Write a haiku about Berlin."}],
"stream": true,
"stream_options": {"include_usage": true}
}'तार प्रारूप
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1710000000,"model":"gpt-5.1-chat","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1710000000,"model":"gpt-5.1-chat","choices":[{"index":0,"delta":{"content":"Cold "},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1710000000,"model":"gpt-5.1-chat","choices":[{"index":0,"delta":{"content":"stone "},"finish_reason":null}]}
…
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1710000000,"model":"gpt-5.1-chat","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":17,"total_tokens":29}}
data: [DONE]POST /v1/messages
Anthropic-संगत संदेश एपीआई। अधिकारी के साथ काम करता है @anthropic-ai/sdk सेटिंग द्वारा baseURL को https://api.airforce. OpenAI/Google/आदि को अग्रेषित करें। गैर-क्लाउड मॉडल के लिए पारदर्शी रूप से।
https://api.airforce/v1/messagesनिकाय से अनुरोध करें
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Required | मॉडल आईडी (Anthropic-प्रारूप या रूटेड उपनाम)। |
| messages | array | Required | प्रत्येक प्रविष्टि: { role: "user" | "assistant", content: string | array }। |
| max_tokens | integer | Required | Anthropic द्वारा आवश्यक। प्रतिक्रिया के लिए टोकन सीमा. |
| system | string | array | Optional | सिस्टम प्रॉम्प्ट। कैश किए गए प्रीफ़िक्स खंडों को चिह्नित करने के लिए { type: "text", text, cache_control? } ब्लॉकों की एक array पास करें। "Prompt caching" देखें। |
| temperature | float | Optional | 0-1. |
| top_p | float | Optional | नाभिक नमूनाकरण. |
| top_k | integer | Optional | सैंपलिंग पूल को टॉप-के टोकन तक सीमित करें। |
| stop_sequences | array | Optional | 4 स्टॉप सीक्वेंस तक। |
| stream | boolean | Optional | सत्य होने पर, Anthropic-शैली एसएसई ईवेंट स्ट्रीम उत्सर्जित करता है ("स्ट्रीमिंग" देखें)। |
| fallbacks | array | Optional | Fallback models (max 3) in Anthropic form: [{"model": "gpt-4o-mini"}]. If every channel of the primary model fails, each candidate is tried in order; you are billed for — and the response model field reports — the model that actually answered. A plain models string array is accepted too. |
| tools | array | Optional | Anthropic टूल परिभाषाएँ: { name, description, input_schema }। प्रतिक्रिया में tool_use कंटेंट ब्लॉक हो सकते हैं। |
| tool_choice | object | Optional | { type: "auto" | "any" | "tool", name? }। |
| thinking | object | Optional | Anthropic विस्तारित थिंकिंग: { type: "enabled", budget_tokens: N }। |
उदाहरण
curl https://api.airforce/v1/messages \
-H "x-api-key: sk-air-YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4.6",
"max_tokens": 256,
"system": "You are a helpful assistant.",
"messages": [
{"role": "user", "content": "Hello, Claude!"}
]
}'प्रतिक्रिया स्वरूप
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | string | Optional | संदेश आईडी, उदा. "msg_01ABCxyz"। |
| type | string | Optional | हमेशा "संदेश"। |
| role | string | Optional | हमेशा "सहायक"। |
| content | array | Optional | कंटेंट ब्लॉकों की array: { type: "text" | "tool_use" | "thinking", … }। |
| model | string | Optional | अनुरोधित मॉडल की प्रतिध्वनि। |
| stop_reason | string | Optional | "अंत_मोड़" | "max_tokens" | "स्टॉप_सीक्वेंस" | "उपकरण_उपयोग"। |
| usage | object | Optional | { input_tokens, output_tokens, cache_read_input_tokens?, cache_creation_input_tokens?, cache_creation? }. कैश फ़ील्ड्स तब दिखाई देते हैं जब प्रॉम्प्ट कैशिंग का उपयोग किया गया। cache_creation.ephemeral_5m_input_tokens और ephemeral_1h_input_tokens प्रति-TTL राइट विभाजन देते हैं। |
स्ट्रीमिंग इवेंट
Anthropic SSE एकबारगी JSON खंडों के बजाय नामित घटनाओं का उपयोग करता है। प्रत्येक घटना में दोनों होते हैं event: नाम और ए data: JSON पेलोड.
event: message_start
data: {"type":"message_start","message":{"id":"msg_01","role":"assistant","content":[],"model":"claude-sonnet-4.6","stop_reason":null,"usage":{"input_tokens":12,"output_tokens":1}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":17}}
event: message_stop
data: {"type":"message_stop"}POST /v1/messages/count_tokens
Anthropic-compatible token counting. Send the same system / messages / tools you would pass to /v1/messages and get an input-token estimate back without running the model — nothing is billed.
https://api.airforce/v1/messages/count_tokenscurl https://api.airforce/v1/messages/count_tokens \
-H "x-api-key: sk-air-YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4.6",
"system": "You are a helpful assistant.",
"messages": [{"role": "user", "content": "Hello, Claude!"}]
}'
# → {"input_tokens": 34}The count is a fast character-based estimate (about 4 characters per token) over system, messages and tools — close enough for context-budget checks, not an exact tokenizer run.
शीघ्र कैशिंग
पर /v1/messages क्लाउड मॉडल के साथ, एक उपसर्ग को पास करके कैश्ड के रूप में चिह्नित करें system ब्लॉकों की एक सरणी के रूप में जहां कैश्ड सेगमेंट चलता है cache_control: { type: "ephemeral" }. बाद के अनुरोध जो समान उपसर्ग से शुरू होते हैं, सस्ती कैश-रीड दर चार्ज करते हैं। के साथ मॉडल supports_caching: true में /v1/models इसका समर्थन करें.
शीघ्र कैशिंग वाले मॉडल
…· live{
"model": "claude-sonnet-4.6",
"max_tokens": 1024,
"system": [
{"type": "text", "text": "You are a senior staff engineer at Airforce."},
{
"type": "text",
"text": "<repository-snapshot>...</repository-snapshot>",
"cache_control": {"type": "ephemeral"}
}
],
"messages": [
{"role": "user", "content": "Where is rate limiting enforced?"}
]
}रिस्पॉन्स में कैश काउंट कैसे रिपोर्ट किए जाते हैं
कैश टोकन काउंट प्रत्येक फॉर्मेट के मूल आकार में पास किए जाते हैं, इसलिए SDK (openai, @anthropic-ai/sdk, @google/genai) उन्हें कस्टम कोड के बिना पढ़ते हैं। जब मान शून्य होता है तो फ़ील्ड छोड़ दिए जाते हैं, जिससे गैर-कैश्ड रिस्पॉन्स हल्के रहते हैं।
/v1/chat/completions (OpenAI आकार)
"usage": {
"prompt_tokens": 2104,
"completion_tokens": 147,
"total_tokens": 2251,
"prompt_tokens_details": { "cached_tokens": 1980 },
"cache_creation_input_tokens": 124,
"cache_creation": {
"ephemeral_5m_input_tokens": 124,
"ephemeral_1h_input_tokens": 0
}
}/v1/messages (Anthropic आकार)
"usage": {
"input_tokens": 2104,
"output_tokens": 147,
"cache_read_input_tokens": 1980,
"cache_creation_input_tokens": 124,
"cache_creation": {
"ephemeral_5m_input_tokens": 124,
"ephemeral_1h_input_tokens": 0
}
}/v1beta/.../generateContent (Gemini आकार)
"usageMetadata": {
"promptTokenCount": 2104,
"candidatesTokenCount": 147,
"totalTokenCount": 2251,
"cachedContentTokenCount": 1980
}कैशिंग कहाँ लागू होती है
Claude मॉडलों के लिए स्पष्ट cache_control मार्कर /v1/messages और /v1/chat/completions दोनों पर मान्य हैं — उन्हें system या message कंटेंट ब्लॉक पर लगाएँ। कई अन्य प्रोवाइडर (OpenAI-परिवार, DeepSeek, Gemini) स्वतः कैश करते हैं: आप कोई मार्कर नहीं भेजते और जैसे ही पर्याप्त लंबा प्रीफ़िक्स दोबारा उपयोग होता है, प्रतिक्रिया में cached_tokens दिख जाता है।
कैश अवधि: 5 मिनट या 1 घंटा
कैश किया गया प्रीफ़िक्स डिफ़ॉल्ट रूप से 5 मिनट जीवित रहता है और हर हिट पर टाइमर रिफ़्रेश होता है। अधिक समय तक रहने वाले प्रीफ़िक्स के लिए मार्कर में ttl: "1h" जोड़ें। प्रतिक्रिया प्रत्येक TTL को cache_creation के अंतर्गत अलग-अलग रिपोर्ट करती है।
"cache_control": { "type": "ephemeral", "ttl": "1h" }उदाहरण: पहले write, फिर read
बिल्कुल वही अनुरोध दो बार भेजें (ऊपर का कैशिंग उदाहरण)। प्रीफ़िक्स को पहली बार देखने वाला कॉल एक बार का cache write चुकाता है; TTL के भीतर समान कॉल बहुत सस्ता cache read चुकाते हैं।
पहला कॉल — cache write (usage अंश):
"usage": {
"input_tokens": 2104,
"output_tokens": 12,
"cache_creation_input_tokens": 1980,
"cache_read_input_tokens": 0
}TTL के भीतर दूसरा समान कॉल — cache read:
"usage": {
"input_tokens": 2104,
"output_tokens": 12,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 1980
}सीमाएँ और लागत
- Claude को न्यूनतम कैश-योग्य प्रीफ़िक्स चाहिए (लगभग 1024 टोकन; कुछ मॉडलों के लिए अधिक)। इससे छोटे प्रीफ़िक्स कैश ही नहीं होते।
- प्रति अनुरोध अधिकतम 4 cache breakpoints, और कैश किया गया प्रीफ़िक्स कॉल के बीच बाइट-दर-बाइट समान होना चाहिए — एक अक्षर का बदलाव भी कैश चूक जाता है।
- Cache writes सामान्य इनपुट से महँगे होते हैं (5m ≈ 1.25×, 1h ≈ 2×); reads बहुत सस्ते (≈ 0.1×)। प्रत्येक मॉडल की कैश कीमतें प्राइसिंग पेज पर देखें।
POST /v1/responses
स्टेटफुल बातचीत के लिए OpenAI Responses-API सतह। समान Bearer/x-api-key प्रमाणीकरण। कैश गणना input_tokens_details.cached_tokens (रीड) प्लस फ्लैट cache_creation_input_tokens + cache_creation.ephemeral_* (राइट्स) के रूप में दिखाई देती है, /v1/chat/completions के साथ समानता के लिए।
https://api.airforce/v1/responsesPOST /v1beta/models/{model}:generateContent
Google Gemini-compatible endpoint. Works with the official @google/genai SDK and the Gemini CLI by pointing the base URL at https://api.airforce/v1beta. Any routed model works — requests are translated to and from the native Gemini shape, and the model is taken from the URL path (not the body).
https://api.airforce/v1beta/models/{model}:generateContentAuthentication
Pass your Airforce API key any of the three ways Google clients use:
# 1) query parameter (Google default)
?key=sk-air-YOUR_API_KEY
# 2) header
x-goog-api-key: sk-air-YOUR_API_KEY
# 3) bearer token
Authorization: Bearer sk-air-YOUR_API_KEYRequest body
| Parameter | Type | Required | Description |
|---|---|---|---|
| contents | array | Required | Conversation turns. Each: { role: "user" | "model", parts: [...] }. A part is { text }, { functionCall: { name, args } }, or { functionResponse: { name, response } }. "model" is Gemini's term for the assistant role. |
| systemInstruction | object | Optional | System prompt: { parts: [{ text }] }. |
| generationConfig | object | Optional | { temperature, maxOutputTokens, topP, stopSequences } — mapped to the canonical sampling parameters. |
| tools | array | Optional | Tool definitions: [{ functionDeclarations: [{ name, description, parameters }] }]. functionDeclarations are flattened across entries. |
| toolConfig | object | Optional | Tool-choice control: { functionCallingConfig: { mode: "AUTO" | "ANY" | "NONE" } }. ANY forces a call, NONE disables tools. |
Example
curl "https://api.airforce/v1beta/models/gemini-3.1-pro:generateContent" \
-H "x-goog-api-key: sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{"role": "user", "parts": [{"text": "What is the capital of France?"}]}
],
"systemInstruction": {"parts": [{"text": "You are a helpful assistant."}]},
"generationConfig": {"temperature": 0.7, "maxOutputTokens": 256}
}'Response shape
| Parameter | Type | Required | Description |
|---|---|---|---|
| candidates | array | Optional | Generated turns: [{ content: { role: "model", parts }, finishReason, index }]. Only the first candidate is populated. |
| candidates[].finishReason | string | Optional | "STOP" | "MAX_TOKENS" | "SAFETY" | "OTHER". |
| usageMetadata | object | Optional | { promptTokenCount, candidatesTokenCount, totalTokenCount, cachedContentTokenCount? }. cachedContentTokenCount appears when the upstream reported a cache read. |
| modelVersion | string | Optional | Echo of the requested model. |
{
"candidates": [{
"content": {
"role": "model",
"parts": [{"text": "The capital of France is Paris."}]
},
"finishReason": "STOP",
"index": 0
}],
"usageMetadata": {
"promptTokenCount": 16,
"candidatesTokenCount": 8,
"totalTokenCount": 24
},
"modelVersion": "gemini-3.1-pro"
}POST /v1beta/models/{model}:streamGenerateContent
Streaming uses the :streamGenerateContent action and returns Server-Sent Events. Each data: line is a full Gemini-shaped chunk (not a delta object); the final chunk carries usageMetadata.
data: {"candidates":[{"content":{"role":"model","parts":[{"text":"The capital"}]},"index":0}],"modelVersion":"gemini-3.1-pro"}
data: {"candidates":[{"content":{"role":"model","parts":[{"text":" is Paris."}]},"index":0}],"modelVersion":"gemini-3.1-pro"}
data: {"candidates":[{"content":{"role":"model","parts":[]},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":16,"candidatesTokenCount":8,"totalTokenCount":24}}List models
The catalog is also exposed in Gemini Model-resource shape so Google clients can enumerate models.
curl https://api.airforce/v1beta/modelsNotes: the base URL is https://api.airforce/v1beta (or /v1), not Google's host. The model name comes from the URL path, not the request body. Only the first candidate is returned, and a subset of Gemini fields is translated — safetySettings and cachedContent are currently ignored. Billing, rate limits and smart routing apply exactly as on /v1/chat/completions.
त्रुटियाँ
Airforce मानक HTTP स्थिति कोड और दोनों समापन बिंदुओं के लिए एक समान त्रुटि लिफाफा लौटाता है।
| Parameter | Type | Required | Description |
|---|---|---|---|
| 400 | invalid_request_error | Optional | विकृत JSON, आवश्यक फ़ील्ड अनुपलब्ध, अज्ञात मॉडल। |
| 401 | invalid_request_error / auth_required | Optional | गुम या अमान्य API कुंजी. |
| 402 | insufficient_quota | Optional | मॉडल के लिए सक्रिय सदस्यता या धनात्मक Pay-as-you-Go बैलेंस आवश्यक है। |
| 403 | model_access_denied / insufficient_scope | Optional | योजना या प्रति-कुंजी अनुमतियाँ इस अनुरोध को अस्वीकार करती हैं। |
| 404 | model_not_found | Optional | अनुरोधित मॉडल मौजूद नहीं है या आपके पास उस तक पहुँच नहीं है। |
| 429 | rate_limit_error | Optional | अनुरोध दर या दैनिक टोकन सीमा पार हो गई है। |
| 503 | api_error / moderation_unavailable | Optional | अनुरोधित प्रदाता के लिए सभी अपस्ट्रीम कुंजियाँ विफल रहीं। |
{
"error": {
"message": "The requested model does not exist or you do not have access to it.",
"type": "model_not_found",
"param": null,
"code": "404"
}
}वर्णनात्मक स्लग type में होता है। code स्ट्रिंग के रूप में HTTP स्टेटस है (जैसे "404"), और param पैरामीटर-रेंज वैलिडेशन त्रुटियों को छोड़कर null होता है, जहाँ यह आपत्तिजनक पैरामीटर का नाम बताता है।
मॉडल खोजें
मॉडल आईडी और उनकी क्षमता झंडे (दृष्टिकोण, उपकरण, तर्क, कैशिंग, संदर्भ लंबाई, ...) की पूरी सूची यहां देखें /docs/api/models.
curl https://api.airforce/v1/models \
-H "Authorization: Bearer sk-air-YOUR_API_KEY"