<p align="center">
  <img src="https://latinfo.dev/logo-badge.svg" alt="latinfo" width="160">
</p>

<h1 align="center">latinfo</h1>

<p align="center">KYB API for Latin American legal entities. 20+ public registry sources for Peru — SUNAT, OSCE, OECE and more. Updated daily, sub-100ms from anywhere.</p>

## Install

```bash
npm install -g @carrerahaus/latinfo
latinfo login
```

`latinfo login` opens GitHub OAuth in your browser and stores your API key in `~/.latinfo/config.json`. Takes 30 seconds.

## Latinfo team: easypipe

Registered Latinfo team members can run imports without receiving R2, Cloudflare,
or shared admin credentials:

```bash
npm install -g @carrerahaus/latinfo@latest
latinfo login
gh auth login

# Existing source
latinfo easypipe build pe-inei-ciiu
latinfo pipe run pe-inei-ciiu

# New or changed source: every remote gate runs the pushed immutable commit
git add <changed-files>
git commit -m "Add source importer"
git push --set-upstream origin HEAD
latinfo pipe test <source>
latinfo pipe validate <source>
latinfo pipe stage <source>
latinfo pipe stage <source> --verify-published <failed-run-id> # resume only post-import verification
latinfo pipe monitor <source> # phase, tmp, disk, stalls, terminal exit code
latinfo pipe docs <source>
latinfo pipe publish <source>
latinfo pipe retire <source> --category <category> --reason <text> --issue <number> --plan
latinfo pipe retire <source> --category <category> --reason <text> --issue <number> --confirm <source>
```

`pipe retire` is the only destructive source-retirement entry point. It requires
an enum category, a concrete 40–500 character reason with meaningful distinct
words, and an existing issue in `carrerahaus/latinfo-api` that explicitly names
the source. It accepts
exactly one source (never `all` or a glob), inventories repository references,
R2/CAS/lake/semantic/sitemap artifacts, an Iceberg table, and the Mint cache,
then requires the complete source name as confirmation. It deploys the source
removal and persistent tombstone before purging data; shared CAS objects and
shared importers are preserved. `--plan` performs the same inventory without
changing anything. Legal files remain as audit evidence.

Allowed categories are `legal`, `privacy`, `license`, `security`,
`upstream-retired`, `superseded`, `quality`, and `operational`. Placeholder,
short, or repetitive reasons fail in both the CLI and admin API. The dedicated
`retire-source` Gate 0 must be activated; `ingest-source` does not authorize a
destructive retirement.

For agent-operated ingestion, bypass any stale global install explicitly:

```bash
npx -y @carrerahaus/latinfo@latest pipe setup-agent --agent codex
# reload, invoke /ingest-source or /retire-source, then activate that exact skill:
npx -y @carrerahaus/latinfo@latest pipe setup-agent --activate --agent codex --skill ingest-source
npx -y @carrerahaus/latinfo@latest pipe setup-agent --activate --agent codex --skill retire-source
```

Use that `npx ... @latest pipe` prefix for the remaining gates in the session.

Current scaffolds use pipe schema v3. Research total uncompressed input, largest
stable partition and peak local working set before creation, then declare the
execution strategy explicitly:

```bash
npx -y @carrerahaus/latinfo@latest pipe create co agency dataset \
  --url https://example.gov/data.csv --id-name nit --id-length 10 \
  --expected-input-gb 12 --max-partition-gb 12 --max-working-set-gb 30 \
  --scale-strategy bounded_local --checkpoint-backend none
```

If the complete input does not fit, use `partitioned_remote` only with a stable
partition key, bounded `max_partition_gb`, idempotent R2 checkpoints and real
resume support. CI rejects unsafe declarations before download and the runtime
watchdog terminates a job that exceeds `max_working_set_gb`.

An admin registers each member once with `latinfo team add <github-username>`.
Every pipe gate checks live membership and GitHub identity, then runs the pushed
immutable commit in GitHub Actions with a short-lived operation-specific grant.
`test` and `validate` receive no R2, Cloudflare, production API, or alert secrets.
Removing the member from the team immediately prevents new grants.

Source configs created by current CLI versions also declare a lightweight
`upstream.healthcheck_url` and the provider's official status page. The trusted
workflow checks availability before assigning a self-hosted runner. Transient
429/5xx/network failures stay attached to the same authorized run and are
requeued without changing its immutable SHA or operation flags.

Long imports are observed through `latinfo pipe monitor`, not manual `sleep`,
`gh` and SSH polling loops. Per-run commit-status telemetry is portable across
AWS and Mint, and the terminal sample confirms whether cleanup reached `tmp 0`.
A blocking monitor has no eight-hour cutoff; it remains open until the workflow
reaches a terminal result.
A coding agent should leave the blocking command in a background terminal; it
does not need an LLM turn to poll it. The monitor prints an ETA range from prior
successful runs with the same source and mode, including sample size and
confidence; it explicitly says when no comparable history exists.

If a stage already committed its manifest/search shards and completed guarded
cleanup but the post-import benchmark was cancelled or failed, recover with
`latinfo pipe stage <source> --verify-published <run-id>`. The CLI, signed grant,
and trusted workflow all bind the exact failed run, immutable source commit,
successful import/upload evidence, and cleanup before rerunning only profile,
search hydration, and benchmark. Any mismatch fails closed and requires a normal
stage rebuild. The prior signed Actions evidence replaces the machine-local
`validate` receipt, so recovery remains portable across agents and worktrees.
A coding agent must not wake every X minutes. It resumes on terminal exit or a
durable `backlog` Issue; if its host cannot surface terminal completion, it uses
the single p75 + 30 minute fallback deadline printed by the CLI. Queue time is
excluded until import telemetry starts. The monitor process may sample status
internally without consuming model turns.
A scheduled GitHub-hosted monitor continues detecting stalls/failures and
queues a deduplicated `backlog` Issue for the next agent after the initiating
agent disconnects.

## CLI

```bash
latinfo pe sunat padron 20100047218              # Lookup by RUC
latinfo pe sunat padron --search "banco credito" # Search by name
latinfo pe osce sanctioned 20100047218           # OSCE sanctions
latinfo sources                                   # List all available sources
```

## SDK

```bash
npm install @carrerahaus/latinfo
```

```typescript
import { Latinfo } from '@carrerahaus/latinfo';

const client = new Latinfo('YOUR_API_KEY');

// Lookup by RUC
const company = await client.pe.ruc('20100047218');
console.log(company.razon_social); // BANCO DE CREDITO DEL PERU

// Search by company name
const results = await client.pe.search('banco de credito');

// Rotate API key
const { api_key } = await client.rotate();
```

Get your API key: `npm install -g @carrerahaus/latinfo && latinfo login`

## API

Base URL: `https://api.latinfo.dev`

```
GET /pe/ruc/:ruc              → Lookup by RUC (11 digits, legal entities only)
GET /pe/search?q=...          → Search by company name
GET /pe/:institution/:dataset/:id → Source-specific lookup
POST /auth/rotate             → Rotate API key
```

```bash
curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.latinfo.dev/pe/ruc/20100047218
```

Full API reference: [latinfo.dev/docs](https://latinfo.dev/docs)

## What you don't have to do

You don't download hundreds of MB from SUNAT, OSCE, or OECE. You don't parse Latin1 with escaped pipe delimiters. You don't write check digit algorithms. You don't build a search index that handles S.A.C. and E.I.R.L. You don't set up daily import pipelines. You don't manage servers.

We do all of that. Daily.

## Pricing

Billed in **credits**: a single-institution lookup or search costs 1 credit; a KYB
costs 1 per government institution it cross-references.

- **Free**: 1,000 credits/month — no credit card
- **Pro**: 50,000 credits/month — $29/month

Live plan limits + your current usage: run `latinfo plan`, or `GET https://api.latinfo.dev/plans`
(the single source of truth — these numbers are read from there, not hardcoded).

## Links

- Website: [latinfo.dev](https://latinfo.dev)
- Docs: [latinfo.dev/docs](https://latinfo.dev/docs)
- Changelog: [latinfo.dev/changelog](https://latinfo.dev/changelog)
- Status: [carrera.instatus.com](https://carrera.instatus.com)
- Email: [hola@latinfo.dev](mailto:hola@latinfo.dev)
