Function calling guide
Listed inFunction CallingWorking with modelson
OpenAI's reference on declaring tools, handling the model's call, strict schemas, and parallel tool use.
Calling them, asking well, and getting output your code can rely on.
Sign in to track your progress across sections.
The request and response shapes of the three major APIs, and what survives a move between them.
7 lessons · 22 min · Working with models
Instructions that survive a model change, an adversarial user and a second reader.
7 lessons · 24 min · Working with models
19 articles
Listed inFunction CallingWorking with modelson
OpenAI's reference on declaring tools, handling the model's call, strict schemas, and parallel tool use.
Listed inFunction CallingWorking with modelson
The model returns a request your code chooses to run. Arguments are model-generated, and providers document the model inventing ones nobody supplied.
Listed inGoogle Gemini APIWorking with modelson
Four safety categories, five thresholds, and a default of OFF. Blocking arrives in a field rather than an exception.
Listed inClaude Messages APIWorking with modelson
The three required parameters include max_tokens, which is optional almost everywhere else. Content comes back as an array of typed blocks, so indexing the first one breaks the day you enable tools.
Listed inOpenAI-Compatible APIsWorking with modelson
Ollama and vLLM both implement a subset of the OpenAI schema and both document what is missing. Unsupported fields are accepted and ignored, so a request that depends on tool_choice succeeds and quietly stops forcing anything.
Listed inOpenAI Responses APIWorking with modelson
OpenAI recommends Responses for all new projects. Instructions move out of the message list, output arrives as a typed array rather than a string, and the server will hold the conversation for you.
Listed inUsing SDKs DirectlyWorking with modelson
The provider client sends the request and hands back the response, including the stop reason and usage figures a wrapper returning a string throws away. What you give up by adding a framework, and what you take on by not.
Listed inPrompt EngineeringWorking with modelson
A dense, well-cited tour of zero-shot, few-shot, chain-of-thought, and automatic prompt search.
Listed inStructured OutputWorking with modelson
Asking for JSON in the prompt, JSON mode, and schema-constrained output give different guarantees. JSON mode promises syntactically valid JSON and not conformance to your schema, which is the gap most applications trip on.
Listed inProviding ContextWorking with modelson
Long documents go above the question, not below it, and the boundary between your instruction and their text is a security control.
Listed inSystem PromptingWorking with modelson
The Messages API takes the system prompt as its own parameter rather than a first message. Putting the date or a user's name in it stops the prefix caching, so you pay the write premium and never collect the read discount.
Listed inChain of ThoughtWorking with modelson
On models that reason by default, asking for step-by-step thinking pays for the steps twice. Carried-over verification instructions cause over-verification, and tag conventions are a weak way to separate reasoning from the answer.
Listed inPrompt EngineeringWorking with modelson
A prompt is a specification written for something with no context on your product. What has to exist before you start, the three failures that look like prompt problems and are not, and the techniques in rough order of payoff.
Listed inZero-Shot PromptingWorking with modelson
Asking cold, with no examples, and when that is genuinely enough.
Listed inConstraintsWorking with modelson
Telling a model what to write beats telling it what to avoid, and a constraint tuned on one model can suppress something the next one needed. Where the line falls between asking and enforcing.
Listed inRole & BehaviorWorking with modelson
A persona works for tone and register and does almost nothing for factual accuracy, since telling a model it is an expert confers no expertise. Describing what to do beats describing who to be, and an identity is a compression the model may unpack differently from how you meant.
Listed inReAct PromptingWorking with modelson
Interleaving reasoning with action means each observation lands before the next decision, so a surprising result changes the next step instead of being absorbed into a plan nobody revisits. The pattern survived; the string parsing it was taught with did not.
Listed inInput FormatWorking with modelson
Pick one markup and use it consistently, because mixing XML tags, markdown headings and JSON gives the model competing signals about where the boundaries are. Ordering matters more than the choice: documents early, the instruction last.
Listed inFew-Shot PromptingWorking with modelson
Anthropic suggests three to five examples, wrapped in tags and varied enough that the model does not learn a pattern you did not intend. Examples are input tokens, so they belong in the cached prefix.