Skip to content

devlog/model-bench/deepseek-v4-pro-backend-code-from-the-terminal-31.md

DeepSeek V4 Pro: Backend Code from the Terminal

DeepSeek V4 Pro: Backend Code from the Terminal

My preferred backend-generation task is deliberately small: one service, one contract, and tests I can inspect before anything runs. This walkthrough asks DeepSeek V4 Pro for a local task API, saves its output, and checks the HTTP behavior. It is a development exercise, not a claim that generated code is production-ready.

Fluxo keeps the connection plumbing in one place: one key and the base URL https://api.fluxorelay.com for Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok, and more. Here, I will use its OpenAI-compatible interface rather than add another provider-specific client.

1. Prepare an isolated Python workspace

Use Bash with Python 3.11 or newer, curl, and Git installed. Run each command paragraph separately. The OpenAI Python SDK supports a custom base URL, environment-based credentials, and configurable timeouts and retries. ([github.com](https://github.com/openai/openai-python))

mkdir fluxo-backend-lab && cd fluxo-backend-lab && git init

python3 -m venv .venv && source .venv/bin/activate && python -m pip install openai

printf '%s\n' '.venv/' '__pycache__/' '.env' 'response.json' 'usage.json' > .gitignore

read -r -s -p 'Fluxo API key: ' OPENAI_API_KEY; echo; export OPENAI_API_KEY

export OPENAI_BASE_URL='https://api.fluxorelay.com' — If you need credentials, you can create a Fluxo account and follow along. Keep the key out of prompts, committed files, and shared terminal recordings.

2. Select the DeepSeek V4 Pro identifier

Do not confuse a shelf label with an API identifier. List the models exposed to your account, then paste the identifier corresponding to DeepSeek V4 Pro. The SDK provides a models-list operation; this check also exercises your credentials before generation. ([github.com](https://github.com/openai/openai-python))

python -c 'from openai import OpenAI; print("\n".join(m.id for m in OpenAI().models.list()))'

read -r -p 'DeepSeek V4 Pro model identifier: ' FLUXO_MODEL; export FLUXO_MODEL

Stop if discovery fails. Resolve the authentication or endpoint error rather than guessing a model slug or repeatedly sending generation requests.

3. Specify the task API before generating code

I want implementation constraints written down before the model chooses architecture. This contract intentionally excludes databases, authentication, and deployment scaffolding.

printf '%s\n' 'Build a Python 3.11 standard-library-only HTTP service. Return only one JSON object with exactly two string-valued keys: app.py and test_app.py. No Markdown fences. app.py must expose make_server(port=0), returning an HTTPServer bound to 127.0.0.1, without starting it. Its main entrypoint serves on port 8000. Implement GET /health returning 200 and {"status":"ok"}; POST /tasks accepting a JSON object with a nonempty string title, returning 201 with integer id and trimmed title; GET /tasks returning a JSON array. Store tasks in memory per server instance. Reject malformed JSON, non-object bodies, and invalid titles with 400. Reject bodies over 16384 bytes with 413. Unknown routes return 404. Send application/json responses. test_app.py must contain at least six unittest HTTP integration tests using an ephemeral port, deterministic cleanup, and isolated state. Include validation and oversized-body cases. Do not access external networks or execute shell commands.' > spec.txt

4. Generate files without executing the response

This request uses the familiar chat-completion message structure. Save the returned text first, and reject an unfinished response rather than trying to repair truncated source automatically. ([api-docs.deepseek.com](https://api-docs.deepseek.com/api/create-chat-completion))

python -c 'import os; from pathlib import Path; from openai import OpenAI; r=OpenAI(timeout=180.0,max_retries=0).chat.completions.create(model=os.environ["FLUXO_MODEL"],messages=[{"role":"user","content":Path("spec.txt").read_text()}],max_tokens=12000); Path("usage.json").write_text(r.usage.model_dump_json() if r.usage else "null"); c=r.choices[0]; c.finish_reason == "stop" or exit("Incomplete generation; inspect usage before retrying"); Path("response.json").write_text(c.message.content or "")'

Parse the JSON and allow only the two expected filenames. JSON decoding validates the wrapper, not the safety or correctness of the generated Python. ([docs.python.org](https://docs.python.org/3/library/json.html))

python -c 'import json; from pathlib import Path; d=json.loads(Path("response.json").read_text()); assert isinstance(d,dict) and set(d)=={"app.py","test_app.py"}; assert all(isinstance(v,str) for v in d.values()); [Path(k).write_text(v) for k,v in d.items()]'

5. Review and test the generated HTTP contract

Read both files before running them. My review checklist stays concrete:

  • Confirm importing either module never starts a background server.
  • Check request validation independently from the generated happy-path tests.
  • Verify cleanup closes sockets even when an assertion fails.

git diff --no-index /dev/null app.py; git diff --no-index /dev/null test_app.py

After review, run the test module using unittest’s command-line interface. ([docs.python.org](https://docs.python.org/3.11/library/unittest.html?utm_source=openai))

python -m unittest -v test_app — Start the service, then use a second terminal for independent smoke checks.

python app.py — curl -i http://127.0.0.1:8000/health

curl -i -H 'Content-Type: application/json' -d '{"title":"Ship backend"}' http://127.0.0.1:8000/tasks

curl -i http://127.0.0.1:8000/tasks

Expect 200, 201, and 200 respectively. If behavior differs, preserve the failing case before requesting a focused correction. I have not executed this account-dependent walkthrough; generated output still needs your verification.

6. Keep DeepSeek V4 Pro iterations measurable

Inspect usage.json after each request. Fluxo bills real tokens, including cache reads and writes, with no monthly fee; do not assume repeated context is free. It also works with Claude Code, Codex, Gemini CLI, and OpenAI SDKs. Referral sharing applies when invited users pay, but my engineering checkpoint remains simpler: reviewed code, independent checks, and a reproducible failure before another generation.

Next in the buffer

Sign up in a minute and get credit to try every model mentioned here. Sign up →