大模型网摘deepseek.wang

Tutorials · 2026-11-22

Python in Practice: Adding File Q&A to DeepSeek via the Full-Stack App API

The most common capability combo in the full-stack app API is "upload a file, then ask questions about it". Since file input opened on November 13, the flow works end to end on the official API: upload and parse via the Files API, take the returned file ID, then attach that ID to the conversation. This tutorial wires the flow in Python — the code is illustrative, and actual endpoints and parameters follow the official documentation.

A Three-Step Flow

The whole chain is three steps. Upload: hand your PDF, Word or image to the file endpoint and let the server parse it. Converse: create the chat with the returned file ID attached. Ask: the model answers based on the parsed content. Most engineering pitfalls concentrate in step one — parsing quality caps everything the model can say afterwards.

Illustrative Code

The sample below shows the full flow, with variable names and response structures simplified:

import requests
BASE = "https://api.deepseek.com" # check official docs
KEY = "your-api-key"

# 1. Upload and parse
files = {"file": open("report.pdf", "rb")}
r = requests.post(f"{BASE}/files", headers={"Authorization": f"Bearer {KEY}"}, files=files).json()
file_id = r["id"]

# 2. Start a chat with the file ID
r2 = requests.post(f"{BASE}/chat/completions",
    headers={"Authorization": f"Bearer {KEY}"},
    json={"model": "deepseek-flash",
          "messages": [{"role": "user",
               "content": "Summarize the three key points of this report"}],
          "file_ids": [file_id]}).json()
print(r2["choices"][0]["message"]["content"])

Two details are worth flagging. First, the model name deepseek-flash refers to the current V4.1 Flash family; compatibility policies for legacy names follow official announcements. Second, the file_ids field is illustrative — the real request schema lives in the official API documentation, and the upload and chat endpoints may name their fields differently.

From One File to a Q&A Service

Once single-file Q&A works, extensions come naturally. Attaching multiple documents to one conversation suits cross-document comparison; combining the standalone OCR endpoint lets scanned pages become text before they enter your store; speech recognition and synthesis cover the "read it to me" scenario, at limited-time promotional prices during the launch period. When calls start failing, our error-code troubleshooting guide maps the usual suspects.

If you combine web retrieval with file Q&A, keep the November 18 billing rule in mind — free when the model triggers search, metered for standalone calls; the choice logic lives in our Search & Fetch standalone guide. New to the DeepSeek API? Start with the Python quickstart, then come back for file capabilities.

Endpoints and pricing follow the official documentation. This article is compiled from publicly available sources.