# gt: General Translation CLI tool: gt auth
URL: https://generaltranslation.com/zh/docs/cli/reference/commands/auth.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 为项目生成 General Translation API 凭据。gt auth 命令的 API 参考。

生成一个 API 密钥和项目 ID，并将其写入你的 `.env.local` 文件。如果 `.env.local` 不存在，该命令会创建该文件，并将其添加到 `.gitignore`。

如果未传入 `--key-type`，该命令会提示你选择要生成的密钥类型。

```bash
npx gt auth
```

## 工作方式 [#how-it-works]

1. 提示你登录 General Translation 仪表板。
2. 生成所需的 API 密钥类型和项目 ID。
3. 如有需要，创建 `.env.local` (并将其添加到 `.gitignore`) 。
4. 将 `GT_API_KEY` 和 `GT_PROJECT_ID` 写入 `.env.local`。

## 标志 [#flags]

| 参数                      | 描述                                          | 类型       | 可选 | 默认               |
| ----------------------- | ------------------------------------------- | -------- | -- | ---------------- |
| `-c, --config <path>`   | 配置文件路径。                                     | `string` | 是  | `gt.config.json` |
| `-t, --key-type <type>` | 要生成的密钥类型：`production`、`development` 或 `all`。 | `string` | 是  | 交互提示             |

## 示例 [#example]

```bash
# 提示输入密钥类型，然后将凭据写入 .env.local
npx gt auth

# 不经提示直接生成生产环境密钥
npx gt auth --key-type production
```

## 其他说明 [#notes]

* 使用 `gt-react` 或 `gt-next` 无需 API 密钥和项目 ID——只有在调用 General Translation API 时才需要。
* `auth` 是 [`gt init`](/docs/cli/reference/commands/init) 向导中的凭据配置步骤。单独运行它，即可为已完成配置的项目生成凭据。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
