Skip to content

Add GitHub token support for semantic search#54

Open
qbradley wants to merge 1 commit into
1st1:mainfrom
qbradley:feature/github-token-support
Open

Add GitHub token support for semantic search#54
qbradley wants to merge 1 commit into
1st1:mainfrom
qbradley:feature/github-token-support

Conversation

@qbradley

@qbradley qbradley commented Apr 2, 2026

Copy link
Copy Markdown

Copilot subscribers can now use their GitHub token for lat search embeddings instead of a separate OpenAI or Vercel API key.

Problem

Semantic search required an OpenAI (sk-...) or Vercel AI Gateway (vck_...) API key. Users with a GitHub Copilot subscription already have access to the same text-embedding-3-small model via the GitHub Models API, but couldn't use it.

Solution

Add a github embedding provider that targets the GitHub Models API at https://models.github.ai/inference/embeddings. The API is OpenAI-compatible, so the existing embed() function works unchanged.

Provider detection recognizes three GitHub token prefixes:

  • ghp_ — classic personal access tokens
  • gho_ — OAuth tokens (returned by gh auth token)
  • github_pat_ — fine-grained personal access tokens

Other changes:

  • Add errorHint field to EmbeddingProvider type, appended to API error messages to give provider-specific troubleshooting guidance
  • Update lat init to accept GitHub tokens with models:read scope guidance and a gh auth token helper tip
  • Update all error messages (Anthropic rejection, unrecognized prefix) to reference GitHub as an option
  • Update README, lat.md/cli.md, and AGENTS.md documentation

Validation

  • 15 provider detection tests (3 new GitHub prefix tests with full config assertions, updated Anthropic/unknown error tests, negative test for ghs_ App tokens)
  • 2 new errorHint integration tests (mock fetch, verify hint appended on error / absent when unset)
  • All 159 tests pass; tsc --noEmit and lat check clean
  • Manually verified with my github subscription using Github Copilot CLI

Copilot subscribers can now use their GitHub token for `lat search`
embeddings instead of a separate OpenAI or Vercel API key.

Problem
-------
Semantic search required an OpenAI (`sk-...`) or Vercel AI Gateway
(`vck_...`) API key. Users with a GitHub Copilot subscription already
have access to the same `text-embedding-3-small` model via the GitHub
Models API, but couldn't use it.

Solution
--------
Add a `github` embedding provider that targets the GitHub Models API at
`https://models.github.ai/inference/embeddings`. The API is
OpenAI-compatible, so the existing `embed()` function works unchanged.

Provider detection recognizes three GitHub token prefixes:
- `ghp_` — classic personal access tokens
- `gho_` — OAuth tokens (returned by `gh auth token`)
- `github_pat_` — fine-grained personal access tokens

Other changes:
- Add `errorHint` field to `EmbeddingProvider` type, appended to API
  error messages to give provider-specific troubleshooting guidance
- Update `lat init` to accept GitHub tokens with `models:read` scope
  guidance and a `gh auth token` helper tip
- Update all error messages (Anthropic rejection, unrecognized prefix)
  to reference GitHub as an option
- Update README, lat.md/cli.md, and AGENTS.md documentation

Validation
----------
- 15 provider detection tests (3 new GitHub prefix tests with full
  config assertions, updated Anthropic/unknown error tests, negative
  test for `ghs_` App tokens)
- 2 new `errorHint` integration tests (mock fetch, verify hint
  appended on error / absent when unset)
- All 159 tests pass; `tsc --noEmit` and `lat check` clean

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vercel

vercel Bot commented Apr 2, 2026

Copy link
Copy Markdown

@qbradley is attempting to deploy a commit to the Yury Selivanov's projects Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread src/cli/init.ts
'), Vercel AI Gateway (' +
styleText('dim', 'vck_...') +
'), or GitHub (' +
styleText('dim', 'ghp_...') +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention all three possible prefixes ghp_... / gho_... / github_pat_... here?

Comment thread tests/search.test.ts

// --- errorHint tests ---

import { embed } from '../src/search/embeddings.js';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move the import to the top?

@lars20070

Copy link
Copy Markdown
Contributor

@qbradley Great solution for avoiding additional OpenAI or Vercel API keys. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants