from quart import Quart, request, Response, jsonify
import httpx
import json
app = Quart(__name__)
DEEPINFRA_API_URL = "https://api.deepinfra.com/v1/openai/chat/completions"
DEFAULT_SYSTEM_PROMPT = "Be a helpful assistant"
DEFAULT_MODEL = "deepseek-ai/DeepSeek-V3.1"
@app.post("/chat")
async def chat():
try:
data = await request.get_json()
messages = data.get("messages", [])
system_prompt = data.get("system_prompt", DEFAULT_SYSTEM_PROMPT)
model = data.get("model", DEFAULT_MODEL)
stream = data.get("stream", True)
if not messages:
return jsonify({"error": "Messages array is required"}), 400
full_messages = [{"role": "system", "content": system_prompt}]
full_messages.extend(messages)
payload = {"model": model, "messages": full_messages, "stream": stream}
if stream:
payload["stream_options"] = {
"include_usage": True,
"continuous_usage_stats": True,
}
headers = {
"Accept-Language": "en-US,en;q=0.5",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Type": "application/json",
"Origin": "https://deepinfra.com",
"Pragma": "no-cache",
"Referer": "https://deepinfra.com/",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"Sec-GPC": "1",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
"X-Deepinfra-Source": "web-page",
"sec-ch-ua": '"Chromium";v="142", "Brave";v="142", "Not_A Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Linux"',
}
if stream:
headers["accept"] = "text/event-stream"
async def generate():
async with httpx.AsyncClient(timeout=60.0) as client:
async with client.stream(
"POST",
DEEPINFRA_API_URL,
json=payload,
headers=headers,
) as response:
if response.status_code != 200:
yield f"data: {json.dumps({'error': 'API request failed'})}\n\n"
return
async for line in response.aiter_lines():
if line:
yield line + "\n"
return Response(
generate(),
mimetype="text/event-stream",
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
)
else:
async with httpx.AsyncClient(timeout=60.0) as client:
response = await client.post(
DEEPINFRA_API_URL, json=payload, headers=headers
)
if response.status_code != 200:
return jsonify({"error": "API request failed"}), 500
return jsonify(response.json())
except httpx.RequestError as e:
return jsonify({"error": f"Request failed: {str(e)}"}), 500
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
app.run()
This is our first API for the channel a DeepSeek-V3.1 AI model API u can simply copy it to make your own API or ask any AI to convert it into a function to directly use it with your bot on 100 members i will bring video generation or phone number details API
Thankyou <3
❤8
Cʟᴏꜱᴇ Rᴏᴜᴛᴇʀ
from quart import Quart, request, Response, jsonify import httpx import json app = Quart(__name__) DEEPINFRA_API_URL = "https://api.deepinfra.com/v1/openai/chat/completions" DEFAULT_SYSTEM_PROMPT = "Be a helpful assistant" DEFAULT_MODEL = "deepseek-ai/DeepSeek…
this api is dead as the provider we were scrapping from blocked free users from making even test request as many of you used it to create your own ai chat bot but if you want same ai chatbot code with newer models like kimi 2.5 qwen bla bla i can make it for you people
❤3