{"id":17593738,"url":"https://github.com/azure-samples/azure-openai-keyless-js","last_synced_at":"2025-04-30T03:47:36.484Z","repository":{"id":259040218,"uuid":"859858554","full_name":"Azure-Samples/azure-openai-keyless-js","owner":"Azure-Samples","description":"Example Azure OpenAI deployment and RBAC role for your user account for keyless access","archived":false,"fork":false,"pushed_at":"2025-02-25T10:22:43.000Z","size":232,"stargazers_count":7,"open_issues_count":0,"forks_count":5,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-30T03:47:28.709Z","etag":null,"topics":["ai-azd-templates","azd-templates","azure","bicep","infrastructure","javascript","keyless","nodejs","openai","secure","template"],"latest_commit_sha":null,"homepage":"","language":"Bicep","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/Azure-Samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-19T12:03:26.000Z","updated_at":"2025-04-14T14:56:05.000Z","dependencies_parsed_at":"2024-10-22T01:39:31.469Z","dependency_job_id":null,"html_url":"https://github.com/Azure-Samples/azure-openai-keyless-js","commit_stats":null,"previous_names":["azure-samples/azure-openai-keyless-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-openai-keyless-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-openai-keyless-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-openai-keyless-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-openai-keyless-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure-Samples","download_url":"https://codeload.github.com/Azure-Samples/azure-openai-keyless-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251638756,"owners_count":21619662,"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":["ai-azd-templates","azd-templates","azure","bicep","infrastructure","javascript","keyless","nodejs","openai","secure","template"],"created_at":"2024-10-22T06:12:53.019Z","updated_at":"2025-04-30T03:47:36.459Z","avatar_url":"https://github.com/Azure-Samples.png","language":"Bicep","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- prettier-ignore --\u003e\n\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"./docs/images/keyless.png\" alt=\"\" align=\"center\" height=\"64\" /\u003e\n\n# Azure OpenAI keyless deployment\n\n[![Open project in GitHub Codespaces](https://img.shields.io/badge/Codespaces-Open-blue?style=flat-square\u0026logo=github)](https://codespaces.new/Azure-Samples/azure-openai-keyless-js?hide_repo_select=true\u0026ref=main\u0026quickstart=true)\n[![Learn Azure Managed Identity](https://img.shields.io/badge/Learn-Tutorial-6F8FAF?style=flat-square\u0026logo=microsoft)](https://learn.microsoft.com/training/modules/intro-azure-openai-managed-identity-auth-javascript/)\n[![Watch to learn more about GenAI with JS on YouTube](https://img.shields.io/badge/YouTube-d95652.svg?style=flat-square\u0026logo=youtube)](https://www.youtube.com/playlist?list=PLlrxD0HtieHi5ZpsHULPLxm839IrhmeDk)\n![Node version](https://img.shields.io/badge/Node.js-\u003e=20-3c873a?style=flat-square)\n[![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](LICENSE)\n\n:star: If you like this sample, star it on GitHub — it helps a lot!\n\n[Overview](#overview) • [Get started](#getting-started) • [Run the sample](#run-the-sample) • [Resources](#resources) • [Guidance](#guidance)\n\n\u003c/div\u003e\n\n## Overview\n\nThis sample shows how to to provision an [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview) account with an [RBAC role](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles) permission for your user account to access, so that you can use the OpenAI API SDKs with [keyless (Entra) authentication](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview). Keyless authentication is a recommended security practice to reduce risks with API keys.\n\n## Getting started\n\nThere are multiple ways to get started with this project.\n\nThe quickest way is to use [GitHub Codespaces](#use-github-codespaces) that provides a preconfigured environment for you. Alternatively, you can [set up your local environment](#use-your-local-environment) following the instructions below.\n\n### Use your local environment\n\nYou need to install following tools to work on your local machine:\n\n- [Node.js LTS](https://nodejs.org/download/)\n- [Azure Developer CLI](https://aka.ms/azure-dev/install)\n- [Git](https://git-scm.com/downloads)\n- [PowerShell 7+](https://github.com/powershell/powershell) _(for Windows users only)_\n  - **Important**: Ensure you can run `pwsh.exe` from a PowerShell command. If this fails, you likely need to upgrade PowerShell.\n  - Instead of Powershell, you can also use Git Bash or WSL to run the Azure Developer CLI commands.\n\nThen you can get the project code:\n\n1. [**Fork**](https://github.com/Azure-Samples/azure-openai-keyless-js/fork) the project to create your own copy of this repository.\n2. On your forked repository, select the **Code** button, then the **Local** tab, and copy the URL of your forked repository.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./docs/images/clone-url.png\" alt=\"Screenshot showing how to copy the repository URL\" width=\"400px\" /\u003e\n\u003c/div\u003e\n3. Open a terminal and run this command to clone the repo: \u003ccode\u003e git clone \u0026lt;your-repo-url\u0026gt; \u003c/code\u003e\n\n### Use GitHub Codespaces\n\nYou can run this project directly in your browser by using GitHub Codespaces, which will open a web-based VS Code:\n\n[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge\u0026label=GitHub+Codespaces\u0026message=Open\u0026color=blue\u0026logo=github)](https://codespaces.new/Azure-Samples/azure-openai-keyless-js?hide_repo_select=true\u0026ref\u0026quickstart=true)\n\n### Use a VSCode dev container\n\nA similar option to Codespaces is VS Code Dev Containers, that will open the project in your local VS Code instance using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).\n\nYou will also need to have [Docker](https://www.docker.com/products/docker-desktop) installed on your machine to run the container.\n\n[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge\u0026label=Dev%20Containers\u0026message=Open\u0026color=blue\u0026logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Azure-Samples/azure-openai-keyless-js)\n\n## Run the sample\n\n### Azure prerequisites\n\n- **Azure account**. If you're new to Azure, [get an Azure account for free](https://azure.microsoft.com/free) to get free Azure credits to get started. If you're a student, you can also get free credits with [Azure for Students](https://aka.ms/azureforstudents).\n- **Azure subscription with access enabled for the Azure OpenAI service**. You can request access with [this form](https://aka.ms/oaiapply).\n- **Azure account permissions**:\n  - Your Azure account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [Role Based Access Control Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview), [User Access Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#user-access-administrator), or [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner). If you don't have subscription-level permissions, you must be granted [RBAC](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview) for an existing resource group and deploy to that existing group by running these commands:\n    ```bash\n    azd env set AZURE_RESOURCE_GROUP \u003cname of existing resource group\u003e\n    azd env set AZURE_LOCATION \u003clocation of existing resource group\u003e\n    ```\n  - Your Azure account also needs `Microsoft.Resources/deployments/write` permissions on the subscription level.\n\n### Costs\n\nPricing varies per region and usage, so it isn't possible to predict exact costs for your usage.\nHowever, you can use the [Azure pricing calculator](https://azure.com/e/43c784eb696e40fb9875c809da1c82cd) for the resources below to get an estimate.\n\n- Azure OpenAI: Standard tier, GPT model. Pricing per 1K tokens used, and at least 1K tokens are used per question. [Pricing](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/)\n\n### Provision Azure OpenAI resources\n\n1. Open a terminal and navigate to the root of the project.\n2. Authenticate with Azure by running `azd auth login`.\n3. Run `azd provision` to provision the Azure resources.\n   - You will be prompted to select a location for your OpenAI resource. If you're unsure of which location to choose, select `eastus2`. See [OpenAI model availability table](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) for more information.\n\nThe deployment process will take a few minutes. Once it's done, a `.env` file will be created in the root folder with the environment variables needed to run the application.\n\n### Run the JavaScript sample\n\nFirst make sure you have provisioned the Azure OpenAI resources, and that you have the `.env` file in the root folder.\n\n1. Run `npm install` to install the dependencies.\n2. Run `npm start` to run the example.\n\nThis will use the [OpenAI SDK](https://github.com/openai/openai-node) to make a request to the OpenAI API and print the response to the console.\n\n### Clean up\n\nTo clean up all the Azure resources created by this sample:\n\n1. Run `azd down --purge`\n2. When asked if you are sure you want to continue, enter `y`\n\nThe resource group and all the resources will be deleted.\n\n## Resources\n\nHere are some resources to learn more about Azure OpenAI and related technologies:\n\n- [Serverless AI Chat sample](https://github.com/Azure-Samples/serverless-chat-langchainjs)\n- [Generative AI with JavaScript](https://github.com/microsoft/generative-ai-with-javascript)\n- [Generative AI For Beginners](https://github.com/microsoft/generative-ai-for-beginners)\n- [Azure OpenAI Service](https://learn.microsoft.com/azure/ai-services/openai/overview)\n- [Chat + Enterprise data with Azure OpenAI and Azure AI Search](https://github.com/Azure-Samples/azure-search-openai-javascript)\n\nYou can also find [more Azure AI samples here](https://github.com/Azure-Samples/azureai-samples).\n\n## Guidance\n\n### Region availability\n\nThis template uses model `gpt-4o-mini` which may not be available in all Azure regions. Check for [up-to-date region availability](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) and select a region during deployment accordingly.\n\nWe recommend using `East US 2` if you're unsure of which region to choose.\n\n### Security\n\nThis template has [Managed Identity](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) built in to eliminate the need for developers to manage these credentials. Applications can use managed identities to obtain Microsoft Entra tokens without having to handle any secrets in the code. Additionally, we're using [Microsoft Security DevOps GitHub Action](https://github.com/microsoft/security-devops-action) to scan the infrastructure-as-code files and generates a report containing any detected issues.\n\nYou can Learn more about using Managed Identity with Azure OpenAI in this [tutorial](https://learn.microsoft.com/training/modules/intro-azure-openai-managed-identity-auth-javascript/).\n\n### Troubleshooting\n\nIf you have any issue when running or deploying this sample, please check the [troubleshooting guide](./docs/troubleshooting.md). If you can't find a solution to your problem, please [open an issue](https://github.com/Azure-Samples/azure-openai-keyless-js/issues) in this repository.\n\n## Contributing\n\nThis project welcomes contributions and suggestions. Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Trademarks\n\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft\ntrademarks or logos is subject to and must follow\n[Microsoft's Trademark \u0026 Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\nAny use of third-party trademarks or logos are subject to those third-party's policies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure-samples%2Fazure-openai-keyless-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure-samples%2Fazure-openai-keyless-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure-samples%2Fazure-openai-keyless-js/lists"}