openai

package
v0.15.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openai is the OpenAI credential provider: project, service account, admin and legacy user API keys.

Every OpenAI key embeds the marker `T3BlbkFJ` ("OpenAI" in base64) at a fixed position, so the scan looks for the marker and checks the exact shape around it; the marker is not a checksum but it removes random look-alikes. Verification is one request that lists models, or the organization's admin keys for an admin key. OpenAI's API cannot revoke a key by itself: revocation goes through the Admin API with an admin key of the organization the leaked key belongs to, which the operator supplies in OPENAI_ADMIN_KEY. With one, patty finds the key in the organization's projects by the redacted value OpenAI shows for each key and deletes it.

Index

Constants

View Source
const (
	// KindProject is a project-scoped key (sk-proj-), the kind the platform issues by default.
	KindProject detect.Kind = "openai-project-key"
	// KindServiceAccount is the key of a project's service account (sk-svcacct-).
	KindServiceAccount detect.Kind = "openai-service-account-key"
	// KindAdmin is an organization admin key (sk-admin-), which manages the
	// organization rather than calling models.
	KindAdmin detect.Kind = "openai-admin-key"
	// KindLegacy is a user key from before projects (sk- and 20 characters
	// on either side of the marker).
	KindLegacy detect.Kind = "openai-legacy-key"
)
View Source
const (
	// AdminKeyEnv is the environment variable Configure reads AdminKey from.
	AdminKeyEnv = "OPENAI_ADMIN_KEY"
)
View Source
const Marker = "T3BlbkFJ"

Marker is what every OpenAI key contains at a fixed position: "OpenAI" in base64. The scan looks for it and checks the shape around it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// BaseURL is the API root, https://api.openai.com by default.
	BaseURL string
	Client  *http.Client
	// AdminKey is an admin key of the operator's organization. It enables
	// deletion of that organization's keys and lets the report name them.
	// Configure reads it from OPENAI_ADMIN_KEY.
	AdminKey string
	// contains filtered or unexported fields
}

Provider implements detect.Provider for OpenAI.

func New

func New() *Provider

New returns a Provider against the public OpenAI API.

func (*Provider) Configure

func (p *Provider) Configure(env func(string) string)

Configure implements detect.Configurable: the admin key comes from OPENAI_ADMIN_KEY.

func (*Provider) DryRunRevoke

func (p *Provider) DryRunRevoke(ctx context.Context, tok detect.Token) error

DryRunRevoke implements detect.DryRunRevoker: it finds the key in the organization exactly as Revoke would, and stops there.

func (*Provider) Find

func (*Provider) Find(content []byte) []detect.Token

Find implements detect.Provider. One substring pass for the marker, then the exact shape around each occurrence: a run of one of the documented lengths on each side, the family prefix before the left run, and no continuation into a longer word on either end.

func (*Provider) Kinds

func (p *Provider) Kinds() []detect.KindInfo

Kinds implements detect.Provider. Project, service account and admin keys are revocable only while an admin key is configured; legacy user keys are not managed by the Admin API at all.

func (*Provider) LocalSources

func (*Provider) LocalSources() detect.LocalSources

LocalSources implements detect.Provider: the environment variables the SDKs read, Codex's credential file (which holds a sign-in as well as a key) and opencode's credential store.

func (*Provider) Name

func (*Provider) Name() string

Name implements detect.Provider.

func (*Provider) Revoke

func (p *Provider) Revoke(ctx context.Context, tokens []detect.Token) error

Revoke implements detect.Revoker by deleting each key through the Admin API, which needs the operator's admin key: OpenAI has no endpoint for reporting a leaked key. Admin keys are found in the organization's admin key list, project and service account keys in the key lists of every project, by the redacted value OpenAI shows for each key. A key no entry matches belongs to another organization and is reported as such, not as revoked. Deletion is final.

func (*Provider) Verify

func (p *Provider) Verify(ctx context.Context, tok detect.Token) detect.Verification

Verify implements detect.Provider with one request: listing models, which every key may do, or listing the organization's admin keys for an admin key, which is the only thing such a key is for and also names it. Only OpenAI's invalid_api_key answer counts as revoked. A 429 is reported as unknown, because a key whose quota is exhausted answers 429 just like a rate-limited one and is still very much live.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL