openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Chat Completions is not returning the metatada

Open juninhodeluca opened this issue 7 months ago • 3 comments

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • [x] This is an issue with the Node library

Describe the bug

Hi, I just noticed the metadata key is not being returned in response object when using the https://api.openai.com/v1/chat/completions endpoint despite of the current references says at Create chat completion

Not sure if this is the right place to open this issue, but the openai-openapi looks a bit older.

Request log

[inx-nlp] [SILLY] [69d528cd4d585c4b66e400cf] runFlowExecutionJobWithAxios: making request to https://api.openai.com/v1/chat/completions with body 
{
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "temperature": 0.8,
    "max_completion_tokens": 4096,
    "store": true,
    "model": "gpt-4.1",
    "messages": [
        {
            "role": "system",
            "content": "give a joke about IT support\n\n\n\n"
        }
    ],
    "metadata": {
        "executionId": "69d528cd4d585c4b66e400cf",
        "jobId": "69d528cd4d585c4b66e400da",
        "taskId": "65d4d28ab7b9b5bc5f77db4d"
    }
}

Response log

[inx-nlp] [INFO] [69d528cd4d585c4b66e400cf] runFlowExecutionJobWithAxios: received response from https://api.openai.com/v1/chat/completions: 
{
    "id": "chatcmpl-DS33ORr15wtnJiC5wIvGLIYtb1ubG",
    "object": "chat.completion",
    "created": 1775577294,
    "model": "gpt-4.1-2025-04-14",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Why did the IT support technician refuse to fix the broken elevator?\n\nBecause he didn’t want to deal with another level of abstraction!",
                "refusal": null,
                "annotations": []
            },
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 19,
        "completion_tokens": 26,
        "total_tokens": 45,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "audio_tokens": 0
        },
        "completion_tokens_details": {
            "reasoning_tokens": 0,
            "audio_tokens": 0,
            "accepted_prediction_tokens": 0,
            "rejected_prediction_tokens": 0
        }
    },
    "service_tier": "default",
    "system_fingerprint": "fp_380a29fa2d"
}

Instead, when calling with Responses API and store: true, the returned object is ok

Response log

{
    "id": "resp_00097c4351f871410069d53151b790819c9c931e89f3e579a2",
    "object": "response",
    "created_at": 1775579473,
    "status": "completed",
    "background": false,
    "billing": {
        "payer": "developer"
    },
    "completed_at": 1775579475,
    "error": null,
    "frequency_penalty": 0,
    "incomplete_details": null,
    "instructions": "give a joke about IT support\n\n\n\n",
    "max_output_tokens": 128000,
    "max_tool_calls": null,
    "model": "gpt-5.4-2026-03-05",
    "output": [
        {
            "id": "rs_00097c4351f871410069d5315235c0819c84437646492af66c",
            "type": "reasoning",
            "summary": []
        },
        {
            "id": "msg_00097c4351f871410069d53153482c819caf49fd07786dee11",
            "type": "message",
            "status": "completed",
            "content": [
                {
                    "type": "output_text",
                    "annotations": [],
                    "logprobs": [],
                    "text": "Why did the IT support tech break up with the printer?\n\nBecause it had too many paper jams and never communicated clearly."
                }
            ],
            "phase": "final_answer",
            "role": "assistant"
        }
    ],
    "parallel_tool_calls": true,
    "presence_penalty": 0,
    "previous_response_id": null,
    "prompt_cache_key": null,
    "prompt_cache_retention": null,
    "reasoning": {
        "effort": "medium",
        "summary": "detailed"
    },
    "safety_identifier": null,
    "service_tier": "default",
    "store": true,
    "temperature": 1,
    "text": {
        "format": {
            "type": "text"
        },
        "verbosity": "medium"
    },
    "tool_choice": "auto",
    "tools": [],
    "top_logprobs": 0,
    "top_p": 0.98,
    "truncation": "disabled",
    "usage": {
        "input_tokens": 17,
        "input_tokens_details": {
            "cached_tokens": 0
        },
        "output_tokens": 61,
        "output_tokens_details": {
            "reasoning_tokens": 31
        },
        "total_tokens": 78
    },
    "user": null,
    "metadata": {
        "executionId": "69d531514d585c4b66e40850",
        "jobId": "69d531514d585c4b66e4085b",
        "taskId": "65d4d28ab7b9b5bc5f77db4d"
    },
    "output_text": "Why did the IT support tech break up with the printer?\n\nBecause it had too many paper jams and never communicated clearly."
}

To Reproduce

Endpoint: https://api.openai.com/v1/chat/completions Model: gpt-4.1 Body:

{
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "temperature": 0.8,
    "max_completion_tokens": 4096,
    "store": true,
    "model": "gpt-4.1",
    "messages": [
        {
            "role": "system",
            "content": "give a joke about IT support\n\n\n\n"
        }
    ],
    "metadata": {
        "executionId": "69d528cd4d585c4b66e400cf",
        "jobId": "69d528cd4d585c4b66e400da",
        "taskId": "65d4d28ab7b9b5bc5f77db4d"
    }
}

OS

ubuntu 24

Node version

24.14

Library version

4.104.0

juninhodeluca avatar Apr 07 '26 16:04 juninhodeluca

EQUIVALENCIAS.docx

diegomontanopsn-max avatar Apr 15 '26 04:04 diegomontanopsn-max

Scope clarification: immediate chat.completions.create() responses are not documented to echo request metadata. However, stored-completion list, retrieve, and update responses can include metadata, while the shared ChatCompletion response schema and generated SDK type do not declare it. Previous references to the request-side metadata field do not resolve this response-side gap. Keeping this issue open to track adding optional metadata to the appropriate stored-completion response schema/types.

HAYDEN-OAI avatar Aug 13 '26 19:08 HAYDEN-OAI

Fixed upstream in the canonical Chat Completions response schema. Stored-completion list, retrieve, and update responses can now expose metadata as an optional nullable response property. Immediate create responses are still not guaranteed to echo request metadata. The generated SDK type will be available after a future regeneration and release.

HAYDEN-OAI avatar Aug 14 '26 21:08 HAYDEN-OAI