[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"navigation":3,"url-settings":86,"blog-\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers":663,"blog-author-\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers":1189,"i-material-symbols:arrow-back-rounded":1201},{"id":4,"extension":5,"footer":6,"header":73,"meta":83,"stem":84,"__hash__":85},"navigation\u002Fdata\u002Fshared\u002Fnavigation.yml","yml",{"brand":7,"columns":13,"legal":63},{"name":8,"tagline":9,"downloadCta":10},"Pieces","The memory layer for modern work.",{"label":11,"href":12},"All downloads","\u002Fdownloads",[14,26,39,51],{"title":15,"links":16},"Product",[17,20,23],{"label":18,"href":19},"Pieces Desktop","\u002F",{"label":21,"href":22},"Pieces Enterprise","\u002Fenterprise",{"label":24,"href":25},"Pieces MCP","\u002Fmcp",{"title":27,"links":28},"Resources",[29,33,36],{"label":30,"href":31,"external":32},"Documentation","url:docs.home",true,{"label":34,"href":35},"Blog","\u002Fblog",{"label":37,"href":38,"external":32},"GitHub","url:github.org",{"title":40,"links":41},"Community",[42,45,48],{"label":43,"href":44,"external":32},"Discord","url:social.discord",{"label":46,"href":47,"external":32},"X \u002F Twitter","url:social.x",{"label":49,"href":50,"external":32},"LinkedIn","url:social.linkedin",{"title":52,"links":53},"Company",[54,57,60],{"label":55,"href":56},"About","\u002Fabout",{"label":58,"href":59},"Updates","\u002Fupdates",{"label":61,"href":62},"Contact","\u002Fcontact",[64,67,70],{"label":65,"href":66},"Privacy Policy","\u002Flegal\u002Fprivacy",{"label":68,"href":69},"Refund Policy","\u002Flegal\u002Frefund",{"label":71,"href":72},"Terms of Service","\u002Flegal\u002Fterms",{"links":74,"signIn":75,"contact":78,"cta":80},[],{"label":76,"href":77},"Sign in","url:portal.home",{"label":79,"href":62},"Get in touch",{"label":81,"href":82},"Download","url:routes.downloads",{},"data\u002Fshared\u002Fnavigation","VdirGIa8cUm6xLprbBeTKcw914JfyJjWfF-9hSVOX5Y",{"id":87,"extension":5,"links":88,"meta":660,"stem":661,"__hash__":662},"urlSettings\u002Fdata\u002Fshared\u002Furls.yml",[89,93,97,101,105,109,113,117,121,125,129,133,137,141,145,149,153,157,161,165,169,173,177,181,185,189,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,256,260,264,268,272,276,280,284,288,292,295,299,303,306,310,314,318,322,326,330,334,338,342,346,350,354,358,362,366,370,374,378,382,386,390,394,398,402,406,410,414,418,422,426,430,434,438,442,446,450,453,457,461,465,469,473,477,480,483,486,489,493,497,500,504,508,512,516,520,524,528,532,536,540,544,548,551,555,559,563,567,571,574,577,580,584,587,591,595,599,603,606,610,614,617,620,623,627,631,635,638,641,644,648,652,656],{"key":90,"label":91,"href":92},"downloads.desktop","Desktop download page","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Fdownload",{"key":94,"label":95,"href":96},"downloads.macOS.dmgArm64","macOS DMG Apple Silicon","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_for_x\u002Fdmg-arm64\u002Fdownload",{"key":98,"label":99,"href":100},"downloads.macOS.dmgIntel","macOS DMG Intel","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_for_x\u002Fdmg\u002Fdownload",{"key":102,"label":103,"href":104},"downloads.macOS.pkg","macOS PKG","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fmacos_packaging\u002Fpkg\u002Fdownload",{"key":106,"label":107,"href":108},"downloads.macOS.universal","Desktop macOS Universal","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_for_x\u002Fmacos-universal\u002Fdownload",{"key":110,"label":111,"href":112},"downloads.macOS.pkgArm64","Desktop macOS PKG Apple Silicon","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fmacos_packaging\u002Fpkg-pfd-arm64\u002Fdownload",{"key":114,"label":115,"href":116},"downloads.macOS.pkgIntel","Desktop macOS PKG Intel","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fmacos_packaging\u002Fpkg-pfd\u002Fdownload",{"key":118,"label":119,"href":120},"downloads.windows.appinstaller","Windows App Installer","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fappinstaller\u002Fpieces_for_x.appinstaller",{"key":122,"label":123,"href":124},"downloads.windows.exe","Windows EXE","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_for_x\u002Fwindows-exe\u002Fdownload",{"key":126,"label":127,"href":128},"downloads.windows.msix","Windows MSIX","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_for_x\u002Fwindows-msix\u002Fdownload",{"key":130,"label":131,"href":132},"downloads.windows.suiteManager","Windows Suite Manager","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_suite_windows\u002Fappinstaller\u002Fdownload",{"key":134,"label":135,"href":136},"downloads.linux.flatpakRepo","Linux Flatpak repository","https:\u002F\u002Fbuilds.pieces.app\u002Fpieces-flatpak-repo\u002Fpieces-flatpak.flatpakrepo",{"key":138,"label":139,"href":140},"downloads.linux.snapDesktop","Linux Snap Desktop","https:\u002F\u002Fsnapcraft.io\u002Fpieces-for-developers",{"key":142,"label":143,"href":144},"downloads.linux.snapPiecesOS","Linux Snap PiecesOS","https:\u002F\u002Fsnapcraft.io\u002Fpieces-os",{"key":146,"label":147,"href":148},"downloads.linux.snap","Desktop Linux Snap package","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fpieces_for_x\u002Fsnap\u002Fdownload",{"key":150,"label":151,"href":152},"downloads.piecesOS.macOS.dmgArm64","PiecesOS macOS DMG Apple Silicon","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fos_server\u002Fdmg-arm64\u002Fdownload",{"key":154,"label":155,"href":156},"downloads.piecesOS.macOS.dmgIntel","PiecesOS macOS DMG Intel","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fos_server\u002Fdmg\u002Fdownload",{"key":158,"label":159,"href":160},"downloads.piecesOS.macOS.universal","PiecesOS macOS Universal","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fos_server\u002Fmacos-universal\u002Fdownload",{"key":162,"label":163,"href":164},"downloads.piecesOS.macOS.pkgArm64","PiecesOS macOS PKG Apple Silicon","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fmacos_packaging\u002Fpkg-pos-launch-only-arm64\u002Fdownload",{"key":166,"label":167,"href":168},"downloads.piecesOS.macOS.pkgIntel","PiecesOS macOS PKG Intel","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fmacos_packaging\u002Fpkg-pos-launch-only\u002Fdownload",{"key":170,"label":171,"href":172},"downloads.piecesOS.windows.appinstaller","PiecesOS Windows App Installer","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fappinstaller\u002Fos_server.appinstaller",{"key":174,"label":175,"href":176},"downloads.piecesOS.windows.exe","PiecesOS Windows EXE","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fos_server\u002Fwindows-exe\u002Fdownload",{"key":178,"label":179,"href":180},"downloads.piecesOS.windows.msix","PiecesOS Windows MSIX","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fos_server\u002Fwindows-msix\u002Fdownload",{"key":182,"label":183,"href":184},"downloads.piecesOS.linux.snap","PiecesOS Linux Snap package","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fos_server\u002Fsnap\u002Fdownload",{"key":186,"label":187,"href":188},"downloads.combined.macOS.appleSilicon","Combined macOS installer Apple Silicon","https:\u002F\u002Fbuilds.pieces.app\u002Fstages\u002Fproduction\u002Fmacos_packaging\u002Fpkg-arm64\u002Fdownload",{"key":190,"label":191,"href":104},"downloads.combined.macOS.intel","Combined macOS installer Intel",{"key":193,"label":194,"href":195},"downloads.guides.macOS","macOS installation guide","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces\u002Fmacos-installation-guide",{"key":197,"label":198,"href":199},"downloads.guides.windows","Windows installation guide","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces\u002Fwindows-installation-guide",{"key":201,"label":202,"href":203},"downloads.guides.linux","Linux installation guide","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces\u002Flinux-installation-guide",{"key":205,"label":206,"href":207},"downloads.guides.piecesOS","PiecesOS manual installation","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fcore-dependencies\u002Fpieces-os\u002Fmanual-installation",{"key":209,"label":210,"href":211},"extensions.chrome","Chrome extension","https:\u002F\u002Fchrome.google.com\u002Fwebstore\u002Fdetail\u002Fpieces-save-code-snippets\u002Figbgibhbfonhmjlechmeefimncpekepm",{"key":213,"label":214,"href":215},"extensions.firefox","Firefox add-on","https:\u002F\u002Faddons.mozilla.org\u002Fen-US\u002Ffirefox\u002Faddon\u002Fpieces-save-code-from-the-web\u002F",{"key":217,"label":218,"href":219},"extensions.edge","Edge add-on","https:\u002F\u002Fmicrosoftedge.microsoft.com\u002Faddons\u002Fdetail\u002Fpieces-save-code-snippet\u002Fhglfimcdgonaeeobjckfdabcldfidmim",{"key":221,"label":222,"href":223},"extensions.vscode","VS Code extension","https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=MeshIntelligentTechnologiesInc.pieces-vscode",{"key":225,"label":226,"href":227},"extensions.visualStudio","Visual Studio extension","https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=MeshIntelligentTechnologiesInc.PiecesVisualStudio",{"key":229,"label":230,"href":231},"extensions.jetbrains","JetBrains plugin","https:\u002F\u002Fplugins.jetbrains.com\u002Fplugin\u002F17328-pieces--save-search-share--reuse-code-snippets",{"key":233,"label":234,"href":235},"extensions.obsidian","Obsidian plugin","https:\u002F\u002Fobsidian.md\u002Fplugins?id=pieces-for-developers",{"key":237,"label":238,"href":239},"extensions.sublime","Sublime package","https:\u002F\u002Fpackagecontrol.io\u002Fpackages\u002FPieces",{"key":241,"label":242,"href":243},"extensions.neovim","Neovim plugin","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fplugin_neo_vim",{"key":245,"label":246,"href":247},"extensions.jupyterlab","JupyterLab plugin","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fjupyterlab-pieces",{"key":249,"label":250,"href":251},"extensions.cli","Pieces CLI","https:\u002F\u002Fpypi.org\u002Fproject\u002Fpieces-cli\u002F",{"key":253,"label":254,"href":255},"docs.home","Documentation home","https:\u002F\u002Fdocs.pieces.app",{"key":257,"label":258,"href":259},"docs.getStarted","Get started docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces",{"key":261,"label":262,"href":263},"docs.api","API docs","https:\u002F\u002Fdocs.pieces.app\u002Fapi",{"key":265,"label":266,"href":267},"docs.desktop.overview","Desktop overview","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop",{"key":269,"label":270,"href":271},"docs.desktop.onboarding","Desktop onboarding","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Fonboarding",{"key":273,"label":274,"href":275},"docs.desktop.timeline","Desktop timeline docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Ftimeline",{"key":277,"label":278,"href":279},"docs.desktop.summaries","Desktop summaries docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Fsingle-click-summaries",{"key":281,"label":282,"href":283},"docs.desktop.search","Desktop conversational search docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Fconversational-search",{"key":285,"label":286,"href":287},"docs.desktop.drive","Desktop drive docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Fdrive",{"key":289,"label":290,"href":291},"docs.desktop.account","Desktop account settings docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fdesktop\u002Fconfiguration\u002Faccount",{"key":293,"label":294,"href":92},"docs.desktop.download","Desktop download docs",{"key":296,"label":297,"href":298},"docs.piecesOS.overview","PiecesOS overview docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fcore-dependencies",{"key":300,"label":301,"href":302},"docs.piecesOS.details","PiecesOS details docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fcore-dependencies\u002Fpieces-os",{"key":304,"label":305,"href":207},"docs.piecesOS.install","PiecesOS install docs",{"key":307,"label":308,"href":309},"docs.piecesOS.quickMenu","PiecesOS quick menu docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fcore-dependencies\u002Fpieces-os\u002Fquick-menu",{"key":311,"label":312,"href":313},"docs.piecesOS.storage","On-device storage docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fcore-dependencies\u002Fon-device-storage",{"key":315,"label":316,"href":317},"docs.piecesOS.troubleshooting","PiecesOS troubleshooting docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fcore-dependencies\u002Fpieces-os\u002Ftroubleshooting",{"key":319,"label":320,"href":321},"docs.mcp.overview","MCP overview docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp",{"key":323,"label":324,"href":325},"docs.mcp.cursor","MCP Cursor docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fcursor",{"key":327,"label":328,"href":329},"docs.mcp.vscode","MCP VS Code docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fvs-code",{"key":331,"label":332,"href":333},"docs.mcp.claudeDesktop","MCP Claude Desktop docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fclaude-desktop",{"key":335,"label":336,"href":337},"docs.mcp.claudeCode","MCP Claude Code docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fclaude-code",{"key":339,"label":340,"href":341},"docs.mcp.claudeCowork","MCP Claude Cowork docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fclaude-cowork",{"key":343,"label":344,"href":345},"docs.mcp.githubCopilot","MCP GitHub Copilot docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fgithub-copilot",{"key":347,"label":348,"href":349},"docs.mcp.goose","MCP Goose docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fgoose",{"key":351,"label":352,"href":353},"docs.mcp.windsurf","MCP Windsurf docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fwindsurf",{"key":355,"label":356,"href":357},"docs.mcp.zed","MCP Zed docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fzed",{"key":359,"label":360,"href":361},"docs.mcp.jetbrains","MCP JetBrains docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fjetbrains-ides",{"key":363,"label":364,"href":365},"docs.mcp.continueDev","MCP Continue docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fcontinue-dev",{"key":367,"label":368,"href":369},"docs.mcp.cline","MCP Cline docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fcline",{"key":371,"label":372,"href":373},"docs.mcp.raycast","MCP Raycast docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fraycast",{"key":375,"label":376,"href":377},"docs.mcp.rovoDevCli","MCP Rovo Dev CLI docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Frovo-dev-cli",{"key":379,"label":380,"href":381},"docs.mcp.openaiCodexCli","MCP OpenAI Codex CLI docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fopenai-codex-cli",{"key":383,"label":384,"href":385},"docs.mcp.googleGeminiCli","MCP Google Gemini CLI docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fgoogle-gemini-cli",{"key":387,"label":388,"href":389},"docs.mcp.amazonQ","MCP Amazon Q docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Famazon-q-developer",{"key":391,"label":392,"href":393},"docs.mcp.chatgptDev","MCP ChatGPT Developer Mode docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fchatgpt-developer-mode",{"key":395,"label":396,"href":397},"docs.mcp.openclaw","MCP OpenClaw docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fopenclaw",{"key":399,"label":400,"href":401},"docs.mcp.mcpRemote","MCP Remote docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fmcp-remote",{"key":403,"label":404,"href":405},"docs.mcp.ngrok","MCP ngrok docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmcp\u002Fngrok-setup",{"key":407,"label":408,"href":409},"docs.troubleshooting.macOS","macOS troubleshooting docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces\u002Ftroubleshooting\u002Fmacos",{"key":411,"label":412,"href":413},"docs.troubleshooting.windows","Windows troubleshooting docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces\u002Ftroubleshooting\u002Fwindows",{"key":415,"label":416,"href":417},"docs.troubleshooting.linux","Linux troubleshooting docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fmeet-pieces\u002Ftroubleshooting\u002Flinux",{"key":419,"label":420,"href":421},"docs.privacy","Privacy and security docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fprivacy-security-your-data",{"key":423,"label":424,"href":425},"docs.support","Support docs","https:\u002F\u002Fdocs.pieces.app\u002Fproducts\u002Fsupport",{"key":427,"label":428,"href":429},"portal.home","Pieces portal","https:\u002F\u002Fportal.pieces.app",{"key":431,"label":432,"href":433},"site.home","Website home","https:\u002F\u002Fpieces.app",{"key":435,"label":436,"href":437},"site.about","About page","https:\u002F\u002Fpieces.app\u002Fabout",{"key":439,"label":440,"href":441},"site.features","Features page","https:\u002F\u002Fpieces.app\u002Ffeatures",{"key":443,"label":444,"href":445},"site.plugins","Plugins page","https:\u002F\u002Fpieces.app\u002Fplugins",{"key":447,"label":448,"href":449},"site.contact","Contact page","https:\u002F\u002Fpieces.app\u002Fcontact",{"key":451,"label":58,"href":452},"site.updates","https:\u002F\u002Fpieces.app\u002Fupdates",{"key":454,"label":455,"href":456},"site.news","News","https:\u002F\u002Fpieces.app\u002Fnews",{"key":458,"label":459,"href":460},"site.events","Community events","https:\u002F\u002Fpieces.app\u002Fcommunity\u002Fevents",{"key":462,"label":463,"href":464},"site.userStories","User stories","https:\u002F\u002Fpieces.app\u002Fuser-stories",{"key":466,"label":467,"href":468},"site.academy","Academy","https:\u002F\u002Fpieces.app\u002Flearn\u002Facademy",{"key":470,"label":471,"href":472},"site.support","Website support","https:\u002F\u002Fpieces.app\u002Fsupport",{"key":474,"label":475,"href":476},"site.standup","Standup","https:\u002F\u002Fpieces.app\u002Fstandup",{"key":478,"label":34,"href":479},"site.blog","https:\u002F\u002Fcode.pieces.app\u002Fblog",{"key":481,"label":43,"href":482},"social.discord","https:\u002F\u002Fdiscord.gg\u002Fgetpieces",{"key":484,"label":46,"href":485},"social.x","https:\u002F\u002Fx.com\u002Fgetpieces",{"key":487,"label":488,"href":485},"social.twitter","Twitter",{"key":490,"label":491,"href":492},"social.instagram","Instagram","https:\u002F\u002Fwww.instagram.com\u002Fgetpieces\u002F",{"key":494,"label":495,"href":496},"social.tiktok","TikTok","https:\u002F\u002Fwww.tiktok.com\u002F@getpieces",{"key":498,"label":49,"href":499},"social.linkedin","https:\u002F\u002Fwww.linkedin.com\u002Fcompany\u002Fgetpieces\u002F",{"key":501,"label":502,"href":503},"social.youtube","YouTube","https:\u002F\u002Fyoutube.com\u002F@getpieces",{"key":505,"label":506,"href":507},"github.org","GitHub organization","https:\u002F\u002Fgithub.com\u002Fpieces-app",{"key":509,"label":510,"href":511},"github.support","GitHub support","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fsupport",{"key":513,"label":514,"href":515},"github.issues","GitHub issues","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fsupport\u002Fissues",{"key":517,"label":518,"href":519},"github.discussions","GitHub discussions","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fsupport\u002Fdiscussions",{"key":521,"label":522,"href":523},"github.documentation","GitHub documentation","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fdocumentation",{"key":525,"label":526,"href":527},"github.opensource","GitHub open source","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fopensource",{"key":529,"label":530,"href":531},"github.sdks.python","Python SDK","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fpieces-os-client-sdk-for-python",{"key":533,"label":534,"href":535},"github.sdks.typescript","TypeScript SDK","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fpieces-os-client-sdk-for-typescript",{"key":537,"label":538,"href":539},"github.sdks.dart","Dart SDK","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fpieces-os-client-sdk-for-dart",{"key":541,"label":542,"href":543},"github.sdks.kotlin","Kotlin SDK","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fpieces-os-client-sdk-for-kotlin",{"key":545,"label":546,"href":547},"github.plugins.obsidian","Obsidian plugin repository","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fobsidian-pieces",{"key":549,"label":550,"href":247},"github.plugins.jupyterlab","JupyterLab plugin repository",{"key":552,"label":553,"href":554},"github.plugins.sublime","Sublime plugin repository","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fplugin_sublime",{"key":556,"label":557,"href":558},"github.plugins.neovim","Neovim plugin repository","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fplugin_neovim",{"key":560,"label":561,"href":562},"github.cliAgent","CLI agent repository","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fcli-agent",{"key":564,"label":565,"href":566},"github.mcpDart","MCP Dart repository","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fmcp_dart",{"key":568,"label":569,"href":570},"github.awesomePieces","Awesome Pieces repository","https:\u002F\u002Fgithub.com\u002Fpieces-app\u002Fawesome-pieces",{"key":572,"label":573,"href":66},"legal.privacyPolicy","Privacy policy",{"key":575,"label":576,"href":69},"legal.refundPolicy","Refund policy",{"key":578,"label":579,"href":72},"legal.terms","Terms",{"key":581,"label":582,"href":583},"legal.security","Legal security","https:\u002F\u002Fpieces.app\u002Flegal\u002Fsecurity",{"key":585,"label":586,"href":503},"videos.youtubeChannel","YouTube channel",{"key":588,"label":589,"href":590},"videos.gettingStartedDesktop","Getting started desktop video","https:\u002F\u002Fyoutu.be\u002FdUr1lRM_TYk",{"key":592,"label":593,"href":594},"videos.snippetDiscoveryxR","Snippet discovery video","https:\u002F\u002Fyoutu.be\u002FG6vb1USw-30",{"key":596,"label":597,"href":598},"sales.bookACall","Book a sales call","https:\u002F\u002Fcalendar.app.google\u002FWVUDtUfNy5Vst3sH7",{"key":600,"label":601,"href":602},"sales.enterprise","Enterprise form","https:\u002F\u002Fgetpieces.typeform.com\u002Fto\u002FaVQFTvpE",{"key":604,"label":605,"href":519},"sales.feedback","Feedback discussions",{"key":607,"label":608,"href":609},"sales.earlyAccess","Early access form","https:\u002F\u002Fgetpieces.typeform.com\u002Fearlyaccess",{"key":611,"label":612,"href":613},"sales.supportEmail","Support email","mailto:support@pieces.app",{"key":615,"label":616,"href":19},"routes.home","Home route",{"key":618,"label":619,"href":56},"routes.about","About route",{"key":621,"label":622,"href":12},"routes.downloads","Downloads route",{"key":624,"label":625,"href":626},"routes.thanks","Post-install thanks route","\u002Finstall\u002Fthanks",{"key":628,"label":629,"href":630},"routes.pricing","Pricing route","\u002Fpricing",{"key":632,"label":633,"href":634},"cta.freeTrial","Start free trial CTA (Pieces Pro) — used by \u002Fcampaigns\u002F* landing pages","https:\u002F\u002Fcampaigns.pieces.app\u002F",{"key":636,"label":637,"href":22},"routes.enterprise","Enterprise route",{"key":639,"label":640,"href":62},"routes.contact","Contact route",{"key":642,"label":643,"href":59},"routes.updates","Updates route",{"key":645,"label":646,"href":647},"routes.migrationError","Migration error route","\u002Fmigration\u002Ferror",{"key":649,"label":650,"href":651},"routes.authenticated","Post-login authenticated route","\u002Fauth\u002Fsigned-in",{"key":653,"label":654,"href":655},"routes.signed-out","Signed out route","\u002Fauth\u002Fsigned-out",{"key":657,"label":658,"href":659},"routes.authentication-error","Authentication error route","\u002Fauth\u002Ferror",{},"data\u002Fshared\u002Furls","NLkVE1lIUws518K-1QsSB6T-GvlXYIzcRL1HDhqarGQ",{"id":664,"title":665,"author":666,"authorPhoto":667,"authorPhotoAlt":668,"authorSlug":669,"body":670,"buttonText":668,"buttonUrl":668,"category":1178,"date":1179,"description":1180,"draft":1181,"editorsPick":1181,"extension":1182,"featured":1181,"image":1183,"imageAlt":668,"meta":1184,"navigation":32,"ogImage":668,"ogImageAlt":668,"path":1185,"seo":1186,"stem":1187,"tags":668,"__hash__":1188},"blog\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers.md","Guide to ChatGPT API Implementation for Developers","Kumar Harsh","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers\u002Fauthor.jpeg",null,"kumar-harsh",{"type":671,"value":672,"toc":1169},"minimark",[673,677,680,685,708,716,721,730,741,749,755,762,768,775,781,784,791,810,816,819,823,850,864,870,873,882,885,888,893,907,918,924,930,934,943,962,974,980,989,992,995,1001,1008,1014,1017,1023,1032,1038,1054,1063,1067,1076,1090,1096,1107,1113,1121,1129,1133,1141,1160],[674,675,676],"p",{},"In a world where technology is evolving at an astounding pace, the ChatGPT API has emerged as a game-changer, opening up a universe of possibilities for developers. The ChatGPT API makes it possible to integrate the power of human-like artificial intelligence into your application.",[674,678,679],{},"In this tutorial, you'll learn how to leverage the ChatGPT API in your application to build a content generation tool that can take requirements for an article from the user and generate an article accordingly.",[681,682,684],"h2",{"id":683},"implementing-the-chatgpt-api-in-your-application","Implementing the ChatGPT API in Your Application",[674,686,687,688,695,696,701,702,707],{},"To start off, you'll need ",[689,690,694],"a",{"href":691,"rel":692},"https:\u002F\u002Fnodejs.org\u002F",[693],"nofollow","Node.js"," installed on your local system. This ChatGPT API guide will use ",[689,697,700],{"href":698,"rel":699},"https:\u002F\u002Fyarnpkg.com\u002F",[693],"Yarn"," to install dependencies in the project, but you're free to use npm or any other package management tool if you wish. Finally, you'll need ",[689,703,706],{"href":704,"rel":705},"https:\u002F\u002Fplatform.openai.com\u002Flogin?launch",[693],"an OpenAI account"," for ChatGPT API access.",[674,709,710,711,715],{},"If you’re using ",[689,712,8],{"href":713,"rel":714},"https:\u002F\u002Fpieces.app\u002F",[693],", the code snippets used throughout the tutorial are linked in the sentences introducing the code.",[717,718,720],"h3",{"id":719},"setting-up-the-starting-app","Setting Up the Starting App",[674,722,723,724,729],{},"To help you get started quickly, the frontend for your content generation tool has already been built. You can clone it by running the following ",[689,725,728],{"href":726,"rel":727},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=6b654eb9f2",[693],"command"," on your local machine:",[731,732,737],"pre",{"className":733,"code":735,"language":736},[734],"language-text","bashgit clone https:\u002F\u002Fgithub.com\u002Fkrharsh17\u002Fcontentgpt.git\n","text",[738,739,735],"code",{"__ignoreMap":740},"",[674,742,743,744,748],{},"Once you've cloned the project, change your terminal's working directory to the project's root directory by running the following ",[689,745,728],{"href":746,"rel":747},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=28974a8acf",[693],":",[731,750,753],{"className":751,"code":752,"language":736},[734],"bashcd contentgpt\n",[738,754,752],{"__ignoreMap":740},[674,756,757,758,748],{},"Next, install the dependencies required for the project by running the following ",[689,759,728],{"href":760,"rel":761},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=ecf04ea751",[693],[731,763,766],{"className":764,"code":765,"language":736},[734],"bashyarn install\n",[738,767,765],{"__ignoreMap":740},[674,769,770,771,748],{},"Once the dependencies are installed, you can run the app using the following ",[689,772,728],{"href":773,"rel":774},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=e6cc498f22",[693],[731,776,779],{"className":777,"code":778,"language":736},[734],"bashyarn dev\n",[738,780,778],{"__ignoreMap":740},[674,782,783],{},"This is what the UI looks like:",[674,785,786],{},[787,788],"img",{"alt":789,"src":790},"App UI.","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers\u002Fimg-001.png",[674,792,793,794,797,798,801,802,804,805,748],{},"You'll find the complete code for this UI in the ",[738,795,796],{},"pages\u002Findex.js"," file. There are three input fields asking the user to enter the title of the article, its pitch, and a preferred word count. Once the user enters these details and clicks the blue button at the end, the app sends a request to its ",[738,799,800],{},"\u002Fapi\u002Fgenerate"," endpoint. This endpoint has not been implemented yet, and this is where you will integrate the ChatGPT API. The app expects the ",[738,803,800],{}," endpoint to respond with a JSON object of the following ",[689,806,809],{"href":807,"rel":808},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=82794e9d14",[693],"format",[731,811,814],{"className":812,"code":813,"language":736},[734],"json\n{\n  \"content\": \"\"}\n",[738,815,813],{"__ignoreMap":740},[674,817,818],{},"You're now ready to integrate the ChatGPT API into your application.",[717,820,822],{"id":821},"chatgpt-api-integration","ChatGPT API Integration",[674,824,825,826,831,832,837,838,843,844,849],{},"There are many ",[689,827,830],{"href":828,"rel":829},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fintroduction",[693],"ChatGPT API endpoints"," to help you add AI capabilities to your application. Each ChatGPT API endpoint is meant for a specific use case. For this article, you'll use the ",[689,833,836],{"href":834,"rel":835},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fchat",[693],"Chat endpoint",". The ",[689,839,842],{"href":840,"rel":841},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fcompletions",[693],"Completions endpoint"," would also fit this use case, but as explained in the ",[689,845,848],{"href":846,"rel":847},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fgpt\u002Fchat-completions-vs-completions",[693],"GPT documentation",", the Chat endpoint is cheaper and offers access to the GPT-3.5 Turbo and GPT-4 APIs, which the Completions endpoint does not.",[674,851,852,853,858,859,748],{},"When working with a large language model (LLM) like GPT, it's very important to ",[689,854,857],{"href":855,"rel":856},"https:\u002F\u002Fwww.forbes.com\u002Fsites\u002Fjodiecook\u002F2023\u002F06\u002F26\u002Fhow-to-write-effective-prompts-for-chatgpt-7-essential-steps-for-best-results\u002F",[693],"phrase your prompts correctly",". For the purposes of this article, you'll instruct the model using the following ",[689,860,863],{"href":861,"rel":862},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=b08646a7e9",[693],"prompts",[731,865,868],{"className":866,"code":867,"language":736},[734],"json\n[\n  {\n    \"role\": \"system\",\n    \"content\": \"You are a content generation tool. After the user provides you with the topic name, article length, and pitch of the article, you will generate the article and respond with ONLY the article in Markdown format and no other extra text.\"\n  },\n  {\n    \"role\": \"user\",\n    \"content\": \"Write an article on the topic . The article should be close to  words in length. Here is a pitch describing the contents of the article: \"\n  }\n]\n",[738,869,867],{"__ignoreMap":740},[674,871,872],{},"This provides the model with two input messages as prompts. The first message defines its functionality, which is to act as a content generation tool and only respond with the desired output, with no other supporting text like \"Sure! Here's your article:\" or anything similar that ChatGPT often includes in its responses. This is a system message, meaning it is an internal instruction provided to the model by the application.",[674,874,875,876,881],{},"The second message asks the model to write the article with the given description. This is a user message, meaning that this is a message given by the user that the model needs to act on (respond to). You can learn more about message roles in ",[689,877,880],{"href":878,"rel":879},"https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F7042661-chatgpt-api-transition-guide",[693],"this transition guide by OpenAI",".",[674,883,884],{},"Feel free to modify the prompt to generate more specific responses. The more specific you are with your prompts, the more likely the model will respond with the correct content.",[674,886,887],{},"Before you begin writing the API calls to interact with the ChatGPT API, you need to first acquire your OpenAI API key.",[889,890,892],"h4",{"id":891},"acquiring-your-openai-api-key","Acquiring Your OpenAI API Key",[674,894,895,896,901,902,906],{},"You'll find your OpenAI API key on the API keys page in your ",[689,897,900],{"href":898,"rel":899},"https:\u002F\u002Fplatform.openai.com\u002Faccount\u002Fapi-keys",[693],"OpenAI account's user settings section",". If you haven't already created an API key, you need to create one by clicking the ",[903,904,905],"strong",{},"Create new secret key"," button. Once you create a new API key, you can only view it once, so make sure to copy and store it somewhere safe.",[674,908,909,910,913,914,748],{},"Once you have your API key, create a new file called ",[738,911,912],{},".env"," in your project and store the key in it in the following ",[689,915,809],{"href":916,"rel":917},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=844b4f892b",[693],[731,919,922],{"className":920,"code":921,"language":736},[734],"bashOPENAI_API_KEY=\n",[738,923,921],{"__ignoreMap":740},[674,925,926,927,881],{},"You will now be able to access this key on your server environment through ",[738,928,929],{},"process.env.OPENAI_API_KEY",[889,931,933],{"id":932},"using-the-rest-api","Using the REST API",[674,935,936,937,942],{},"You can now proceed to write the logic for using ChatGPT API in your app. To learn how to integrate the Chat endpoint, you'd typically have to consult the API reference for the ChatGPT API. However, to avoid the manual labor of researching the method, you're going to put ",[689,938,941],{"href":939,"rel":940},"https:\u002F\u002Fpieces.app\u002Fblog\u002Fintroducing-pieces-copilot",[693],"Pieces Copilot"," to work.",[674,944,945,946,949,950,955,956,961],{},"If you aren't already aware, ",[689,947,8],{"href":713,"rel":948},[693]," is a developer productivity tool that helps you organize and enrich code snippets so you can refer back to them and share them easily. To take your developer productivity up a notch, Pieces recently introduced their copilot, a chatbot that leverages AI and a contextual understanding of your workflow through ",[689,951,954],{"href":952,"rel":953},"https:\u002F\u002Fpieces.app\u002Fblog\u002Fretrieval-augmented-generation-for-curation",[693],"retrieval augmented generation"," to help you find solutions and implementations quickly as you develop your app. With Pieces, you can also leverage ",[689,957,960],{"href":958,"rel":959},"https:\u002F\u002Fpieces.app\u002Fblog\u002Fsoft-skills-for-software-developers-to-adopt",[693],"novel AI"," prompts that no other AI tool can handle.",[674,963,964,965,970,971,748],{},"To try it out, you first need to ",[689,966,969],{"href":967,"rel":968},"https:\u002F\u002Fdocs.pieces.app\u002Finstallation-getting-started\u002Fwhat-am-i-installing",[693],"set up Pieces",". Once you have the Pieces desktop app installed, you can navigate to the Pieces Copilot section by clicking ",[903,972,973],{},"Go To... > Copilot Chats",[674,975,976],{},[787,977],{"alt":978,"src":979},"Navigating to Copilot.","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers\u002Fimg-002.png",[674,981,982,983,988],{},"You'll be presented with a chat screen. You can now type the following ",[689,984,987],{"href":985,"rel":986},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=28774a9b81",[693],"message"," to ask Pieces Copilot to provide you with the process of integrating ChatGPT API in your Next.js app:",[674,990,991],{},"textHow to integrate the ChatGPT REST API in a Next.js app through server functions? Make use of inbuilt packages only and do not install any external dependenciesCopy And SaveShareAsk Copilot",[674,993,994],{},"You'll notice that Pieces Copilot explains the complete process in detail, with instructions to set up both the client and server logic:",[674,996,997],{},[787,998],{"alt":999,"src":1000},"Pieces Copilot's response.","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers\u002Fimg-003.png",[674,1002,1003,1004,748],{},"You can further shorten this output by sending the following text as the next ",[689,1005,987],{"href":1006,"rel":1007},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=9b36498724",[693],[731,1009,1012],{"className":1010,"code":1011,"language":736},[734],"textProvide the server-side code only\n",[738,1013,1011],{"__ignoreMap":740},[674,1015,1016],{},"You'll notice now that the copilot provides you with just the right server-side code to help set up the integration in your demo app:",[674,1018,1019],{},[787,1020],{"alt":1021,"src":1022},"Refined response.","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers\u002Fimg-004.png",[674,1024,1025,1026,1031],{},"With some modifications, this is how the ",[689,1027,1030],{"href":1028,"rel":1029},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=f6b24b9b57",[693],"final code snippet"," should look:",[731,1033,1036],{"className":1034,"code":1035,"language":736},[734],"js\nexport default function handler(req, res) {\n  const {\n    title, purpose, length\n  } = JSON.parse(req.body)\n  const baseURL = \"https:\u002F\u002Fapi.openai.com\u002Fv1\"\n  const endpoint = \"\u002Fchat\u002Fcompletions\"\n  const apiKey = process.env.OPENAI_API_KEY\n  const requestBody = {\n    \"model\": \"gpt-3.5-turbo\",\n    \"messages\": [\n      {\n        \"role\": \"system\",\n        \"content\": \"You are a content generation tool. After the user provides you with the topic name, article length, and pitch of the article, you will generate the article and respond with ONLY the article in Markdown format and no other extra text.\"\n      },\n      {\n        \"role\": \"user\",\n        \"content\": \"Write an article on the topic \\\"\" + title + \"\\\". The article should be close to \" + length + \" words in length. Here is a pitch describing the contents of the article: \" + purpose\n      }\n    ],\n    max_tokens: length * 1.5\n  }\n  fetch(baseURL + endpoint, {\n    method: \"POST\",\n    body: JSON.stringify(requestBody),\n    headers: {\n      \"Authorization\": \"Bearer \" + apiKey,\n      \"Content-Type\": 'application\u002Fjson'\n    }\n  }).then(r => r.json())\n     .then(r => {\n        console.log(r)\n        res.status(200).json({content: r.choices[0].message.content})\n    })\n    .catch(e => {\n      console.log(e)\n      res.status(500).json({content: \"The article could not be generated. Error: \" + JSON.stringify(e)})\n    })\n}\n",[738,1037,1035],{"__ignoreMap":740},[674,1039,1040,1041,1044,1045,1048,1049,881],{},"You'll need to save this snippet in the ",[738,1042,1043],{},"pages\u002Fapi\u002Fgenerate.js"," file in your Next.js project. You can now run the app using the ",[738,1046,1047],{},"yarn dev"," command, and ",[689,1050,1053],{"href":1051,"rel":1052},"http:\u002F\u002Fttps\u002F\u002Fi.imgur.com\u002FdcD6nyZ.gif",[693],"this is how the tool should run",[674,1055,1056,1057,1062],{},"Pieces Copilot can do much more than code generation. Use it in your browser to explain code snippets you find online, or in your IDE to help you understand entire repositories. Plus, it leverages both cloud and ",[689,1058,1061],{"href":1059,"rel":1060},"https:\u002F\u002Fpieces.app\u002Fblog\u002Flocal-large-language-models-lllms-and-copilot-integrations",[693],"local LLMs",", so you can choose which LLM to use to answer questions and generate code, depending on your security constraints. For enterprise customers, we offer the option of inputting your custom API key into Pieces as well.",[889,1064,1066],{"id":1065},"using-the-nodejs-platform-library","Using the Node.js Platform Library",[674,1068,1069,1070,1075],{},"As you saw in the code snippet above, the REST API can be quite cumbersome to manage, and when working on real-world projects, you will most likely need to write a wrapper over the API so you can use it conveniently in your projects. That said, OpenAI offers a range of ",[689,1071,1074],{"href":1072,"rel":1073},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Flibraries",[693],"platform-specific libraries"," that you can use instead to ease your development process.",[674,1077,1078,1079,1084,1085,1089],{},"For this tutorial, you'll use the ",[689,1080,1083],{"href":1081,"rel":1082},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Flibraries\u002Fnode-js-library",[693],"Node.js library"," offered by OpenAI. To install it, run the following ",[689,1086,728],{"href":1087,"rel":1088},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=8cf64ebe91",[693]," in your project's root directory:",[731,1091,1094],{"className":1092,"code":1093,"language":736},[734],"bashyarn add openai\n",[738,1095,1093],{"__ignoreMap":740},[674,1097,1098,1099,1101,1102,748],{},"Next, replace the code in the ",[738,1100,1043],{}," file with the following ",[689,1103,1106],{"href":1104,"rel":1105},"https:\u002F\u002Fkumar.pieces.cloud\u002F?p=afda4888a7",[693],"snippet",[731,1108,1111],{"className":1109,"code":1110,"language":736},[734],"js\n\u002F\u002F Import the package\nconst OpenAI = require(\"openai\")\nexport default function handler(req, res) {\n    const {\n        title, purpose, length\n    } = JSON.parse(req.body)\n    \u002F\u002F Initialize the package with the API key\n    const openai = new OpenAI({\n        apiKey: process.env.OPENAI_API_KEY,\n    });\n    \u002F\u002F The body remains the same as with the REST API\n    const requestBody = {\n        \"model\": \"gpt-3.5-turbo\",\n        \"messages\": [\n            {\n                \"role\": \"system\",\n                \"content\": \"You are a content generation tool. After the user provides you with the topic name, article length, and pitch of the article, you will generate the article and respond with ONLY the article in Markdown format and no other extra text.\"\n            },\n            {\n                \"role\": \"user\",\n                \"content\": \"Write an article on the topic \\\"\" + title + \"\\\". The article should be close to \" + length + \" words in length. Here is a pitch describing the contents of the article: \" + purpose\n            }\n        ],\n    }\n    \u002F\u002F Instead of making a fetch call, you use the package's method instead\n    openai.chat.completions.create(requestBody)\n        .then(completion => {\n            console.log(completion)\n            res.status(200).json({content: completion.choices[0].message.content})\n        })\n        .catch(e => {\n            console.log(e)\n            res.status(500).json({content: \"The article could not be generated. Error: \" + JSON.stringify(e)})\n        })\n}\n",[738,1112,1110],{"__ignoreMap":740},[674,1114,1115,1116,881],{},"You can now restart your dev server and try running the app once again. It should continue to function normally. This is because the integration logic remained the same even though you changed from the REST API to the Node.js package in the implementation. ",[689,1117,1120],{"href":1118,"rel":1119},"https:\u002F\u002Fi.imgur.com\u002F7Z90QVE.gif",[693],"See it in action here",[674,1122,1123,1124,881],{},"You've now successfully integrated the ChatGPT API into a content generation app. Feel free to play around with the demo app, try out different GPT models, or add more specificity to your prompts to gain better results. You can find the complete code for the application on the completed branch of ",[689,1125,1128],{"href":1126,"rel":1127},"https:\u002F\u002Fgithub.com\u002Fkrharsh17\u002Fcontentgpt\u002Ftree\u002Fcompleted",[693],"this GitHub repo",[681,1130,1132],{"id":1131},"conclusion","Conclusion",[674,1134,1135,1136,1140],{},"This article demonstrated how to use the ChatGPT API in your Next.js app using the REST API and the Node.js SDK. Along the way, you also learned how to use ",[689,1137,941],{"href":1138,"rel":1139},"https:\u002F\u002Fdocs.pieces.app\u002Ffeatures\u002Fpieces-copilot",[693]," to enhance your productivity by quickly generating code through it instead of spending time sifting through ChatGPT API documentation.",[674,1142,1143,1144,1147,1148,1153,1154,1159],{},"Developer productivity is the core focus of all products and services offered by ",[689,1145,8],{"href":713,"rel":1146},[693],". You can also try out the ",[689,1149,1152],{"href":1150,"rel":1151},"https:\u002F\u002Fdocs.pieces.app\u002Fextensions-plugins\u002Fteams",[693],"Microsoft Teams integration"," that Pieces offers to enable you to ask code-related questions and generate code right from your Microsoft Teams workspace. Make sure you try out Pieces and ",[689,1155,1158],{"href":1156,"rel":1157},"https:\u002F\u002Fdocs.pieces.app\u002Fproduct-highlights-and-benefits\u002Fsaving-useful-developer-materials",[693],"save API references in Pieces"," to stay organized.",[674,1161,1162,1163,1168],{},"If you enjoyed working with the ChatGPT API, we’d love to have you ",[689,1164,1167],{"href":1165,"rel":1166},"https:\u002F\u002Fdiscord.com\u002Finvite\u002Fgetpieces",[693],"join our Discord community"," where you can leverage our open source endpoints to build an even more advanced chatbot within your application.",{"title":740,"searchDepth":1170,"depth":1170,"links":1171},2,[1172,1177],{"id":683,"depth":1170,"text":684,"children":1173},[1174,1176],{"id":719,"depth":1175,"text":720},3,{"id":821,"depth":1175,"text":822},{"id":1131,"depth":1170,"text":1132},"Software Development","2023-12-07T00:00:00.000Z","This article offers a guide to implement the ChatGPT API in applications, covering setup, integration steps, and leveraging AI for content generation.",false,"md","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers\u002Fhero.jpeg",{},"\u002Fblog\u002Fguide-to-chatgpt-api-implementation-for-developers",{"title":665,"description":1180},"blog\u002Fguide-to-chatgpt-api-implementation-for-developers","5wmM7cJ35MkjzpD-fXsnKIPrh1oGfPJX0I5uuTmRca0",{"id":1190,"title":666,"body":1191,"description":740,"draft":1181,"extension":1182,"meta":1195,"navigation":32,"path":1196,"photo":1197,"photoAlt":668,"seo":1198,"stem":1199,"__hash__":1200},"authors\u002Fauthors\u002Fkumar-harsh.md",{"type":671,"value":1192,"toc":1193},[],{"title":740,"searchDepth":1170,"depth":1170,"links":1194},[],{},"\u002Fauthors\u002Fkumar-harsh","https:\u002F\u002Fstorage.googleapis.com\u002Fpieces-marketing-website\u002Fimages\u002Fauthors\u002Fplaceholder.svg",{"title":666,"description":740},"authors\u002Fkumar-harsh","TPdGu9SUnGqz41IS9JChZxjAFKsYYImzlYTImybsvzs",{"left":1202,"top":1202,"width":1203,"height":1203,"rotate":1202,"vFlip":1181,"hFlip":1181,"body":1204},0,24,"\u003Cpath fill=\"currentColor\" d=\"m7.825 13l4.9 4.9q.3.3.288.7t-.313.7q-.3.275-.7.288t-.7-.288l-6.6-6.6q-.15-.15-.213-.325T4.426 12t.063-.375t.212-.325l6.6-6.6q.275-.275.688-.275t.712.275q.3.3.3.713t-.3.712L7.825 11H19q.425 0 .713.288T20 12t-.288.713T19 13z\"\u002F>"]