{"id":13602152,"url":"https://github.com/openai/openai-quickstart-node","last_synced_at":"2025-05-13T21:07:06.818Z","repository":{"id":38891898,"uuid":"450291588","full_name":"openai/openai-quickstart-node","owner":"openai","description":"Node.js example app from the OpenAI API quickstart tutorial","archived":false,"fork":false,"pushed_at":"2025-01-23T16:36:12.000Z","size":125,"stargazers_count":2573,"open_issues_count":1,"forks_count":1994,"subscribers_count":102,"default_branch":"master","last_synced_at":"2025-04-28T13:59:33.408Z","etag":null,"topics":["openai","openai-api"],"latest_commit_sha":null,"homepage":"https://platform.openai.com/docs/quickstart?context=node","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-20T23:34:55.000Z","updated_at":"2025-04-27T21:38:18.000Z","dependencies_parsed_at":"2024-09-21T10:30:29.286Z","dependency_job_id":"fb7804ba-9e5f-49fb-b27e-0306b8fdfc53","html_url":"https://github.com/openai/openai-quickstart-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fopenai-quickstart-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fopenai-quickstart-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fopenai-quickstart-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fopenai-quickstart-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openai","download_url":"https://codeload.github.com/openai/openai-quickstart-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254028798,"owners_count":22002277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openai","openai-api"],"created_at":"2024-08-01T18:01:15.352Z","updated_at":"2025-05-13T21:07:01.805Z","avatar_url":"https://github.com/openai.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","A01_文本生成_文本对话","Tutorials","Code Samples"],"sub_categories":["大语言对话模型及数据"],"readme":"# OpenAI API Quickstart - Node.js\n\nThis repository provides a collection of examples demonstrating how to use the OpenAI APIs with the Node.js SDK.\n\nThe examples are organized by API, with each folder dedicated to a specific API:\n\n- Chat Completions\n- Assistants\n- Fine-tuning\n- Embeddings\n- Moderation\n- Batch Processing\n- Images\n\nWithin each folder, you'll find a basic example to get started. For some APIs, additional examples are also included to explore more advanced use cases.\n\n## Prerequisites\n\nTo run the examples with the Node.js SDK, you will need:\n\n- A recent version of [Node.js](https://nodejs.org/) (\u003e= 16.0.0)\n- A recent version of [npm](https://www.npmjs.com/) or another node package manager\n- An OpenAI API key (you can get one from your [OpenAI dashboard](https://platform.openai.com/settings/organization/api-keys))\n\n## How to use\n\n1. Clone this repository\n\n   ```bash\n   $ git clone https://github.com/openai/openai-quickstart-node.git\n   ```\n\n2. Navigate into the project directory\n\n   ```bash\n   $ cd openai-quickstart-node\n   ```\n\n3. Install the OpenAI Node.js SDK\n\n   ```bash\n   $ npm install openai\n   ```\n\n4. Set your OpenAI API key in environment variables\n\n   **In the terminal session:**\n\n   Bash (Mac/Linux):\n\n   ```bash\n   $ export OPENAI_API_KEY=\u003cyour-api-key\u003e\n   ```\n\n   PowerShell (Windows):\n\n   ```bash\n   $ setx OPENAI_API_KEY \"\u003cyour_api_key\u003e\"\n   ```\n\n   **Set it globally:**\n\n   Add this line to your `.bashrc` or `.zshrc` file on Mac/Linux:\n\n   ```bash\n   $ export OPENAI_API_KEY=\u003cyour-api-key\u003e\n   ```\n\n   Or update your system environment variables on Windows.\n\n5. Run each script individually\n\n   ```bash\n   $ node path/to/script.js\n   ```\n\n   For example, to run the basic chat completions example:\n\n   ```bash\n   $ node chat_completions/index.js\n   ```\n\n## Examples\n\nExplore the examples below to learn how to use the Node.js SDK for your specific use case.\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eAPI\u003c/th\u003e\n    \u003cth\u003eExample\u003c/th\u003e\n    \u003cth\u003ePath\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"4\"\u003eChat Completions\u003c/td\u003e\n    \u003ctd\u003eBasic example\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/chat_completions/index.js\"\u003echat_completions/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eMulti-turn conversation\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/chat_completions/multi_turn.js\"\u003echat_completions/multi_turn.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n    \u003ctr\u003e\n    \u003ctd\u003eFunction Calling\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/chat_completions/function_calling.js\"\u003echat_completions/function_calling.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eVision (image input)\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/chat_completions/vision.js\"\u003echat_completions/vision.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\"\u003eAssistants\u003c/td\u003e\n    \u003ctd\u003eCreate an assistant\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/assistants/index.js\"\u003eassistants/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eExample thread\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/assistants/thread.js\"\u003eassistants/thread.js {assistant-id}\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \u003ctd rowspan=\"2\"\u003eFine-tuning\u003c/td\u003e\n  \u003ctd\u003eCreate a fine-tuned model\u003c/td\u003e\n  \u003ctd\u003e\u003ca href=\"/fine_tuning/index.js\"\u003efine_tuning/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eUse a fine-tuned model\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/fine_tuning/use_model.js\"\u003efine_tuning/use_model.js {job-id}\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"1\"\u003eEmbeddings\u003c/td\u003e\n    \u003ctd\u003eGenerate embeddings\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/embeddings/index.js\"\u003eembeddings/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\"\u003eModeration\u003c/td\u003e\n    \u003ctd\u003eModerate text\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/moderation/index.js\"\u003emoderation/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eModerate images \u0026 text\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/moderation/images.js\"\u003emoderation/images.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\"\u003eBatch\u003c/td\u003e\n    \u003ctd\u003eCreate a batch job\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/batch/index.js\"\u003ebatch/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eGet batch job results\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/batch/retrieve_results.js\"\u003ebatch/retrieve_results.js {job-id}\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"1\"\u003eImages\u003c/td\u003e\n    \u003ctd\u003eGenerate an image\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"/images/index.js\"\u003eimages/index.js\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Additional Resources\n\nFor more in-depth examples within front-end applications, including with streaming responses, check out these additional resources:\n\n- [Assistants API Quickstart](https://github.com/openai/openai-assistants-quickstart)\n- [Sample apps with Structured Outputs](https://github.com/openai/openai-structured-outputs-samples)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenai%2Fopenai-quickstart-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenai%2Fopenai-quickstart-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenai%2Fopenai-quickstart-node/lists"}