Skip to main content
Glama

Run an OpenAI chat completion

openai_chat_completion

Send a saved conversation to an OpenAI model and get the next assistant reply. Use this for structured chat history where you need verbatim continuation with controls like stop, temperature, or JSON.

Instructions

Send an explicit list of chat messages to an OpenAI model through the Chat Completions API.

Use this when you already hold a structured conversation history (system/user/assistant turns) and want it sent verbatim. For new single-prompt generations prefer openai_generate_text.

Args:

  • messages (array, required): [{ role: 'system'|'user'|'assistant'|'developer', content: string }], 1-200 entries

  • model (string): model ID, defaults to OPENAI_DEFAULT_TEXT_MODEL

  • max_completion_tokens (number): 1-200000

  • temperature (number): 0-2

  • top_p (number): 0-1

  • stop (string[]): up to 4 stop sequences

  • response_format ('markdown'|'json'): default 'markdown'

Returns (JSON format): { "id": string, // completion ID "model": string, // model that served the request "finish_reason": string | null, // "stop", "length", "content_filter", ... "content": string, // assistant reply text "refusal": string | null, // set when the model declined "usage": { "input_tokens": number|null, "output_tokens": number|null, "total_tokens": number|null } }

Examples:

  • Use when: replaying a saved conversation with a new final user turn

  • Use when: you need a stop sequence to cut generation at a delimiter

  • Don't use when: chaining stored responses (use openai_generate_text with previous_response_id)

Error Handling:

  • "Error: OpenAI rejected the request as invalid" often means an unsupported parameter for that model, e.g. temperature on a reasoning-only model

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stopNoUp to 4 strings that stop generation when produced
modelNoModel ID. Defaults to OPENAI_DEFAULT_TEXT_MODEL.
top_pNoNucleus sampling cutoff
messagesYesConversation history in chronological order
temperatureNoSampling temperature
response_formatNoOutput format: 'markdown' for a readable summary, 'json' for the full structured payloadmarkdown
max_completion_tokensNoUpper bound on generated tokens

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
modelYes
usageYes
contentYes
refusalYes
finish_reasonYes

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observedv1.0.0

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations are minimal (readOnlyHint false, idempotentHint false, destructiveHint false), so the description carries most of the burden. It adds genuinely useful behavioral context beyond annotations: the refusal field populated when the model declines, finish_reason values, nullability of usage tokens, and an error-handling note explaining that 'invalid request' usually means an unsupported parameter for that model. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but remarkably well structured: purpose, usage, args, returns, examples, error handling, with the most decision-relevant information front-loaded in the first two sentences. The Args and Returns blocks partially duplicate the 100%-covered schema and the output schema, which costs some efficiency, but every unique section (examples, error handling) earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter tool with an output schema, the description covers all essentials: purpose, when to use and not use, parameter defaults, full return shape including edge cases (refusal, null usage), and the most common failure mode. Minor gaps remain — no mention of auth prerequisites or rate limits — but those are typically server-side concerns for an MCP wrapper.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The Args section essentially mirrors the schema's constraints (ranges, defaults, max items) without adding new semantic meaning; the schema's response_format description is actually richer than the description's terse version. The description adds no parameter insight beyond what structured data already provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The first sentence names a specific verb and resource: send an explicit list of chat messages through the Chat Completions API. It immediately distinguishes itself from the sibling openai_generate_text ('For new single-prompt generations prefer openai_generate_text'), so an agent can tell them apart without opening either schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives explicit when-to-use conditions (holding structured conversation history, needing verbatim replay, needing stop sequences), explicit when-not-to-use conditions (chaining stored responses), and names the alternative tool in each case. Nothing is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/piorkowskim79/openai-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server