AI Code Review Tutorial Part 4: Understanding the Basic Format of Large‑Model API Calls
This article explains how to integrate a large‑model AI service by constructing the standard HTTP request payload with system, user, and assistant messages, details the key request parameters, and shows how to parse the non‑streaming and streaming response structures using the Zhipu AI Node.js SDK.
In the previous tutorial we built a lightweight AI Code Review project using Node.js and Zhipu AI, without any Java backend. This section concentrates on the technical details of how the AI model is connected, specifically the request and response formats.
Basic integration
Communicating with a large‑model AI is essentially sending an HTTP synchronous request or an SSE streaming request and receiving the model’s answer. The core of the interaction is a JSON payload that contains a messages array.
Request structure
A typical request looks like this:
messages = [
{"role": "system", "content": "You are a marketing expert who can answer any user question."},
{"role": "user", "content": "Please create an attractive slogan for my product."},
{"role": "assistant", "content": "Sure, please tell me more about your product."},
{"role": "user", "content": "My product is a tool for developing XXXXX."},
{"role": "assistant", "content": "Super powerful, making innovation within reach!"}
]The system role sets the AI’s behavior and context, the user role carries the actual prompt, and the assistant role contains the model’s reply. Supplying additional historical messages enriches the conversation context.
Key request parameters
Besides the messages array, most providers require parameters such as model (the name of the model to invoke), temperature, max_tokens, etc. These fields follow a common standard across LLM services, as illustrated in the documentation screenshot below.
Response structure
For a non‑streaming call the generated text is located at: response.choices[0].message.content When using the streaming (SSE) endpoint the incremental token appears at:
response.choices[0].delta.contentSDK insight
Inspecting the zhipuai-sdk-nodejs-v4 source reveals that the SDK creates a Completions object whose create method assembles exactly the JSON payload shown above. This demonstrates that the same pattern can be reproduced in other languages, for example a Java SDK, by mirroring the SDK’s design.
Conclusion
Understanding the standard request and response format makes integrating any LLM—whether for AI‑assisted code review or other AI‑driven features—straightforward, as the only requirement is to construct the correct JSON payload and parse the returned message.content (or delta.content for streaming).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ubiquitous Tech
A ubiquitous public account for pirate enthusiasts, regularly sharing curated experiences, tech learning, and growth insights. Currently publishing articles on AI RAG customer service, AI MCP technology, and open-source design. Personal free Knowledge Planet: Awakening New World Programmer.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
