技能 编程开发 Glean API认证与配置指南

Glean API认证与配置指南

v20260423
glean-install-auth
本指南详细介绍了如何为Glean企业级搜索平台进行API认证和配置。它涵盖了为数据索引(Indexing API)和搜索查询(Client API)设置独立的认证令牌和环境变量,是开发人员进行自定义数据源集成和构建高级搜索功能的核心步骤。
获取技能
466 次下载
概览

Glean Install & Auth

Overview

Configure Glean API authentication for enterprise search and knowledge management. Glean has two APIs: the Indexing API (push content into search) and the Client API (search and retrieve). Each uses separate tokens. Base URL: https://<domain>-be.glean.com/api.

Prerequisites

  • Glean enterprise account with admin access
  • API token from Glean Admin > API Tokens
  • Your Glean deployment domain (e.g., company-be.glean.com)

Instructions

Step 1: Obtain API Tokens

Navigate to Glean Admin Console > Settings > API:

Token Type Purpose Required Header
Indexing API token Push documents into search index Authorization: Bearer <token>
Client API token Search, chat, user-scoped queries Authorization: Bearer <token> + X-Glean-Auth-Type: BEARER

Step 2: Configure Environment Variables

# .env (NEVER commit)
GLEAN_DOMAIN=company-be.glean.com
GLEAN_INDEXING_TOKEN=glean_idx_...
GLEAN_CLIENT_TOKEN=glean_cli_...
GLEAN_DATASOURCE=custom_app  # Your custom datasource name

Step 3: Install SDK and Verify

npm install @anthropic-ai/glean-indexing-api-client  # Or use fetch directly
const GLEAN_BASE = `https://${process.env.GLEAN_DOMAIN}/api`;

// Verify indexing API access
async function verifyIndexingAccess() {
  const res = await fetch(`${GLEAN_BASE}/index/v1/getdatasourceconfig`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.GLEAN_INDEXING_TOKEN}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ datasource: process.env.GLEAN_DATASOURCE }),
  });
  const config = await res.json();
  console.log(`Connected. Datasource: ${config.name}`);
}

// Verify client API access
async function verifySearchAccess() {
  const res = await fetch(`${GLEAN_BASE}/client/v1/search`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.GLEAN_CLIENT_TOKEN}`,
      'X-Glean-Auth-Type': 'BEARER',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ query: 'test', pageSize: 1 }),
  });
  const results = await res.json();
  console.log(`Search works. Found ${results.results?.length ?? 0} results.`);
}

Error Handling

Error Code Cause Solution
Unauthorized 401 Invalid token Regenerate in Admin > API Tokens
Forbidden 403 Token lacks scope Use correct token type (indexing vs client)
Not Found 404 Wrong domain Verify GLEAN_DOMAIN includes -be suffix

Resources

Next Steps

After auth, proceed to glean-hello-world for your first index and search.

信息
Category 编程开发
Name glean-install-auth
版本 v20260423
大小 3.46KB
更新时间 2026-04-28
语言