Why Does a Direct Model API Call Perform Worse Than a Chat Interface?

    A chat interface typically adds system instructions, conversation history, environment context, tool orchestration, and output constraints around the model. This article explains why direct API calls may produce less useful or less stable results, with a focus on information extraction and relation extraction. It also presents a practical prompt structure and an evaluation method based on Precision, Recall, and F1 score.

    1. The Same Model, Two Different Experiences

    Many developers find that a model performs well in a chat interface but produces vague answers or inconsistent formats when called through an API. The difference is especially noticeable in information extraction tasks. A common assumption is that the model is not capable enough or that the prompt is poorly written. In practice, the two usage patterns are often separated by an additional layer of product orchestration.

    A model only generates text based on its input. A chat product typically performs substantial work before and after the model call: assembling system instructions, preserving conversation history, parsing uploaded files, invoking search, deciding whether to enable reasoning, and enforcing output and safety rules.

    A direct API call usually executes only the request submitted by the caller. If the caller does not include certain context or constraints, the model has no way to know them.

    2. The Difference Comes from the Layer Around the Model

    2.1 Runtime Environment Information

    Chat products often attach information such as the current date, the user’s region, and the interface language to each request. Models do not have a built-in clock and do not automatically know a user’s identity or location. Without this information, they can only provide generic answers. Questions involving “today,” “local,” or “recent” are particularly likely to be misinterpreted.

    API callers need to add this information to the system instruction or user message themselves:

    1. from datetime import datetime, timezone
    2. def build_system_prompt(locale: str) -> str:
    3. now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
    4. return (
    5. f"Current time: {now}. "
    6. f"User language: {locale}. "
    7. "回答应直接、准确,不确定时明确说明。"
    8. )

    The Chinese instruction in the original code should be expressed in English when used in an English application:

    1. from datetime import datetime, timezone
    2. def build_system_prompt(locale: str) -> str:
    3. now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
    4. return (
    5. f"Current time: {now}. "
    6. f"User language: {locale}. "
    7. "Answer directly and accurately. Clearly state when you are uncertain."
    8. )

    2.2 Conversation History

    Most model APIs are stateless. The server does not remember what was said in previous turns. The caller must combine the message history in the correct order and send it with each request.

    Chat products handle this process automatically, which makes the model appear to have memory. When using an API, developers must maintain the message list themselves and control its length to avoid exceeding the context window.

    2.3 System Instructions and Role Definition

    The system instructions used by chat products often define the model’s role, tone, safety boundaries, and formatting preferences. These instructions strongly influence default behavior.

    If an API call sends only a single user question, the model has fewer constraints. Its response will therefore be more like a general-purpose conversation rather than a carefully controlled task output.

    2.4 Tools and Retrieval

    Some services expose capabilities such as web search, file parsing, link reading, and deeper reasoning through APIs. However, these capabilities generally need to be enabled explicitly by the caller.

    The caller must also determine how search results are inserted into the context and when a tool should be invoked. The existence of a capability does not mean it will be activated automatically.

    2.5 Output Constraints

    A chat interface can allow the model to add explanations and supplementary notes, which may improve the reading experience. In structured tasks, however, extra text can break downstream parsing.

    API calls should define an explicit output protocol, including fixed fields, fixed data types, and a clear representation for missing values.

    3. Why Relation Extraction Is More Sensitive to Orchestration

    Chat-based interaction encourages the model to understand and explain text. Relation extraction requires the model to be restrained:

    • Do not infer or add relationships that are not stated in the source text.
    • Preserve entity direction. For example, “A acquired B” and “B acquired A” represent different relationships.
    • Do not add fields outside the predefined schema.
    • When the relationship cannot be determined, return an empty value instead of guessing.

    If a prompt uses an open-ended conversational style, the model may interpret “understand this text” as permission to elaborate freely. Relation extraction prompts should therefore replace open-ended questions with explicit rules and constraints.

    4. Divide the Prompt into Five Parts

    A relation extraction prompt should be consistently divided into the following five parts:

    1. Entity types and an allowed relationship list: Only predefined entity types and relationships may be used.
    2. Direction and decision criteria for each relationship: Specify the subject, object, and conditions under which the relationship is valid.
    3. Rules for empty values: If the relationship cannot be confirmed, return an empty value and do not guess.
    4. Evidence from the source text: Include the source span that supports each extracted relationship.
    5. A fixed JSON Schema and boundary examples: Define the output structure and provide two or three positive and negative examples.

    An example output structure is:

    1. {
    2. "relations": [
    3. {
    4. "subject": "Zhang San",
    5. "relation": "employed by",
    6. "object": "Company A",
    7. "evidence": "Zhang San joined Company A in 2020 as an engineer."
    8. }
    9. ]
    10. }

    When no relationship can be determined, the model should return "relations": [] while keeping the field structure unchanged.

    5. Evaluate with Controlled Variables

    Comparing one chat response with one API response does not provide enough evidence. A more reliable approach is to control the variables:

    • Use the same model and the same reasoning mode.
    • Use the same set of sentences with gold-standard annotations prepared in advance.
    • Use the same output protocol and parsing program.
    • Call the model multiple times for each sample and analyze the distribution of results.

    Calculate the metrics as follows:

    • Precision = Number of correctly extracted relationships / Total number of relationships output by the model
    • Recall = Number of correctly extracted relationships / Total number of relationships in the gold-standard answer
    • F1 = 2 × Precision × Recall / (Precision + Recall)

    When comparing prompt versions, evaluate both the F1 score and the distribution of error types.

    If Precision is high but Recall is low, the rules are often too strict and the model is reluctant to output relationships. If Recall is high but Precision is low, the model is likely guessing, so the empty-value rules should be strengthened.

    6. Practical Recommendations

    • Assemble environment information, conversation history, and system instructions as explicit inputs instead of relying on the model to know them implicitly.
    • Verify the activation status of each required external capability rather than assuming that it is enabled by default.
    • Use a fixed schema for structured tasks, and validate the output and retry when necessary at the application level.
    • Build a small annotated dataset and track Precision, Recall, and F1 as prompts and orchestration logic evolve.

    The performance of an API call depends heavily on how much context and how many constraints the caller provides. Model capability is the foundation, but orchestration and output control determine whether the final result is stable and usable.