Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2aronS Duel Agents checkConnectivity

From Leeroopedia
Knowledge Sources
Domains Networking, Configuration
Last Updated 2026-10-27 14:00 GMT

Overview

Concrete tool for probing the Duel API to confirm a key is accepted, trying multiple read-only endpoints and classifying the outcome into a structured result, provided by @duel-agents/core.

Description

The checkConnectivity function probes the Duel proxy with the user's API key to verify that the key is accepted and the service is reachable. It tries three read-only endpoints in sequence: /models (GET), /health (GET), and root HEAD. Each attempt carries the key in an Authorization: Bearer header with a 15-second timeout via AbortSignal.timeout.

The function never throws: all exceptions are caught and folded into a ConnectivityResult. The result's status field distinguishes four outcomes:

  • "ok" — a 2xx response was received; key accepted
  • "unauthorized" — a 401/403 was received; key rejected by server
  • "invalid_key" — key failed local format validation (no network attempt)
  • "unreachable" — all attempts failed (network error or non-definitive HTTP status)

A definitive result (2xx or 401/403) short-circuits the loop. Non-definitive statuses (e.g., 404, 500) fall through to the next attempt.

Usage

Import this function when you need to:

  • Verify a key is accepted after install
  • Build a "doctor" or diagnostics command
  • Distinguish "bad key" from "bad network" for user-facing guidance

Code Reference

Source Location

  • Repository: Duel-Agents
  • File: packages/core/src/config.ts (lines 174-242)

Signature

export interface ConnectivityResult {
  ok: boolean;
  status: "ok" | "unauthorized" | "unreachable" | "invalid_key";
  message: string;
  httpStatus?: number;
}

export async function checkConnectivity(
  apiKey: string,
  proxyUrl?: string,           // default: getProxyUrl()
): Promise<ConnectivityResult>;

Import

import { checkConnectivity, type ConnectivityResult } from "@duel-agents/core";

I/O Contract

Inputs

Name Type Required Description
apiKey string Yes Duel key to verify
proxyUrl string No Proxy URL (default getProxyUrl())

Outputs

Name Type Description
returns Promise<ConnectivityResult> Never throws; all failures folded into result

Usage Examples

Verify Key After Install

import { checkConnectivity } from "@duel-agents/core";

const result = await checkConnectivity(apiKey);
if (result.ok) {
  console.log(`✓ ${result.message}`);
} else if (result.status === "unauthorized") {
  console.error(`✗ ${result.message}`);  // key rejected
} else if (result.status === "invalid_key") {
  console.error(`✗ ${result.message}`);  // malformed locally
} else {
  console.warn(`⚠ ${result.message}`);   // network issue, retry later
}

Custom Proxy URL

import { checkConnectivity } from "@duel-agents/core";

const result = await checkConnectivity(apiKey, "https://staging.duelagents.com/v1");

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment