Working with models

Calling them, asking well, and getting output your code can rely on.

Sign in to track your progress across sections.

Courses in this topic

Practice in this topic

19 articles

Function Calling

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.

Reference
Intermediate4 min
#api
#security

Claude Messages API

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.

Reference
Beginner3 min
#api

OpenAI-Compatible APIs

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.

Reference
Intermediate3 min
#api
#portability

OpenAI Responses API

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.

Reference
Beginner3 min
#api

Using SDKs Directly

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.

Reference
Beginner3 min
#sdk

Structured Output

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.

Guide
Intermediate4 min
#prompting
#api

System Prompting

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.

Guide
Beginner3 min
#prompting

Chain of Thought

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.

Guide
Intermediate3 min
#prompting
#reasoning

Prompt Engineering

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.

Guide
Beginner3 min
#prompting

Constraints

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.

Guide
Beginner3 min
#prompting

Role & Behavior

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.

Guide
Beginner4 min
#prompting

ReAct Prompting

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.

Guide
Intermediate4 min
#prompting
#agents

Input Format

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.

Guide
Beginner4 min
#prompting

Few-Shot Prompting

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.

Guide
Beginner3 min
#prompting