[{"data":1,"prerenderedAt":161},["ShallowReactive",2],{"term-c\u002Fchat-completion":3,"related-c\u002Fchat-completion":140},{"id":4,"title":5,"acronym":6,"body":7,"category":119,"description":120,"difficulty":121,"extension":122,"letter":123,"meta":124,"navigation":125,"path":126,"related":127,"seo":134,"sitemap":135,"stem":138,"subcategory":6,"__hash__":139},"terms\u002Fterms\u002Fc\u002Fchat-completion.md","Chat Completion",null,{"type":8,"value":9,"toc":113},"minimark",[10,15,19,23,26,30,102,106,109],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"Chat Completion is the API pattern for having a back-and-forth conversation with an AI. You send an array of messages (user says X, assistant says Y, user says Z) and the AI generates the next message. It's the fundamental API call behind every chatbot, coding assistant, and AI feature you've ever built.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"The Chat Completions API (used by OpenAI, Anthropic, and others) accepts a list of messages with roles (system, user, assistant) and returns the model's next message. It is the dominant interface for LLM integration, supporting multi-turn conversation, system prompts, tool use, and streaming. Most AI products are built on top of this pattern.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","response = client.chat.completions.create(\n    model=\"gpt-4o\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"What is 2+2?\"},\n        {\"role\": \"assistant\", \"content\": \"4\"},\n        {\"role\": \"user\", \"content\": \"Now multiply that by 10.\"}\n    ]\n)\nprint(response.choices[0].message.content)\n","python","",[38,39,40,48,54,60,66,72,78,84,90,96],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"response = client.chat.completions.create(\n",[41,49,51],{"class":43,"line":50},2,[41,52,53],{},"    model=\"gpt-4o\",\n",[41,55,57],{"class":43,"line":56},3,[41,58,59],{},"    messages=[\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},"        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n",[41,67,69],{"class":43,"line":68},5,[41,70,71],{},"        {\"role\": \"user\", \"content\": \"What is 2+2?\"},\n",[41,73,75],{"class":43,"line":74},6,[41,76,77],{},"        {\"role\": \"assistant\", \"content\": \"4\"},\n",[41,79,81],{"class":43,"line":80},7,[41,82,83],{},"        {\"role\": \"user\", \"content\": \"Now multiply that by 10.\"}\n",[41,85,87],{"class":43,"line":86},8,[41,88,89],{},"    ]\n",[41,91,93],{"class":43,"line":92},9,[41,94,95],{},")\n",[41,97,99],{"class":43,"line":98},10,[41,100,101],{},"print(response.choices[0].message.content)\n",[11,103,105],{"id":104},"when-youll-hear-this","When You'll Hear This",[16,107,108],{},"\"The frontend calls the chat completion endpoint.\" \u002F \"Chat completion supports multi-turn conversations.\"",[110,111,112],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":50,"depth":50,"links":114},[115,116,117,118],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":104,"depth":50,"text":105},"ai","Chat Completion is the API pattern for having a back-and-forth conversation with an AI.","beginner","md","c",{},true,"\u002Fterms\u002Fc\u002Fchat-completion",[128,129,130,131,132,133],"Streaming","System Prompt","API Key","Token","LLM","Prompt",{"title":5,"description":120},{"changefreq":136,"priority":137},"weekly",0.7,"terms\u002Fc\u002Fchat-completion","GBOtNF4cP447tCSLk1iAfAU_yhTRTDD0t1zZpllnYes",[141,144,148,151,154,157],{"title":130,"path":142,"acronym":6,"category":119,"difficulty":121,"description":143},"\u002Fterms\u002Fa\u002Fapi-key","An API key is your password to use an AI service. You include it in every request to prove you're allowed to use the API and so they know who to charge.",{"title":132,"path":145,"acronym":146,"category":119,"difficulty":121,"description":147},"\u002Fterms\u002Fl\u002Fllm","Large Language Model","An LLM is a humongous AI that read basically the entire internet and learned to predict what words come next, really really well.",{"title":133,"path":149,"acronym":6,"category":119,"difficulty":121,"description":150},"\u002Fterms\u002Fp\u002Fprompt","A prompt is the message you send to an AI to get it to do something. 'Write me a poem about JavaScript' — that's a prompt.",{"title":128,"path":152,"acronym":6,"category":119,"difficulty":121,"description":153},"\u002Fterms\u002Fs\u002Fstreaming","Streaming is when the AI sends you its response word by word as it generates, instead of making you wait for the whole thing at once.",{"title":129,"path":155,"acronym":6,"category":119,"difficulty":121,"description":156},"\u002Fterms\u002Fs\u002Fsystem-prompt","A system prompt is the secret instruction manual you give the AI before the conversation starts. It sets the personality, rules, knowledge, and behavior.",{"title":131,"path":158,"acronym":6,"category":159,"difficulty":121,"description":160},"\u002Fterms\u002Ft\u002Ftoken","vibecoding","In AI-land, a token is a chunk of text — roughly 3\u002F4 of a word.",1776518264836]