The main API client — manage projects, tickets, agents, and test cases programmatically.

CodmirClient

The CodmirClient class provides typed access to the Codmir REST API. Use it to manage projects, create tickets, delegate tasks to AI agents, and run test suites — all from code.

import { CodmirClient } from '@codmir/sdk';

Constructor

new CodmirClient(config?: CodmirClientConfig)

CodmirClientConfig

ParameterTypeDefaultDescription
apiKeystringprocess.env.CODMIR_API_KEYYour API key
baseUrlstringhttps://codmir.com/apiAPI base URL
timeoutnumber30000Request timeout in ms
headersRecord<string, string>{}Additional headers
const client = new CodmirClient({
  apiKey: process.env.CODMIR_API_KEY,
  baseUrl: 'https://codmir.com/api',
  timeout: 30000,
});

Authentication

whoami()

Returns the authenticated user.

const user = await client.whoami();
// { id, email, name, avatar, role }

Projects

listProjects()

const projects = await client.listProjects();

getProject(projectId)

const project = await client.getProject('proj_abc123');

createProject(input)

const project = await client.createProject({
  name: 'My App',
  description: 'Production web application',
  repositoryUrl: 'https://github.com/org/my-app',
});

Tickets

listTickets(projectId)

const tickets = await client.listTickets('proj_abc123');

createTicket(projectId, input)

const ticket = await client.createTicket('proj_abc123', {
  title: 'Fix login redirect on mobile Safari',
  description: 'OAuth callback fails in cross-origin iframe',
  type: 'bug',
  priority: 'high',
});

CreateTicketInput:

FieldTypeRequiredDescription
titlestringYesTicket title
descriptionstringNoDetailed description
type'feature' | 'bug' | 'refactor' | 'docs' | 'test' | 'chore'NoTicket type
priority'low' | 'medium' | 'high' | 'critical'NoPriority level
labelsstring[]NoLabels to apply
assigneeIdstringNoUser or agent to assign

updateTicket(ticketId, input)

const updated = await client.updateTicket('ticket_xyz', {
  status: 'in_progress',
  assigneeId: 'agent_001',
});

AI Agents

createAgentTask(input)

Delegate a task to an AI agent. The agent will investigate, write code, run tests, and create a PR.

const task = await client.createAgentTask({
  projectId: 'proj_abc123',
  ticketId: 'ticket_xyz',
  type: 'bug_fix',
  instructions: 'Fix the Safari login redirect. Use postMessage instead of window.location.',
});

Test Cases

listTestCases(projectId)

const tests = await client.listTestCases('proj_abc123');

createTestCase(input)

const testCase = await client.createTestCase({
  projectId: 'proj_abc123',
  title: 'Login redirect works on Safari',
  steps: [
    'Navigate to /login',
    'Click "Sign in with Google"',
    'Complete OAuth flow in iframe',
    'Verify redirect to /dashboard',
  ],
  expectedResult: 'User lands on dashboard without blank screen',
});

getCoverageInsights(projectId, request)

AI-generated analysis of your test coverage gaps.

const insights = await client.getCoverageInsights('proj_abc123', {
  scope: 'auth',
  depth: 'detailed',
});

Error Handling

All methods throw CodmirApiError on failure:

import { CodmirApiError } from '@codmir/sdk';

try {
  await client.createTicket('proj_abc123', { title: 'Bug' });
} catch (error) {
  if (error instanceof CodmirApiError) {
    console.error(error.status);   // HTTP status code
    console.error(error.message);  // Error message
    console.error(error.code);     // Error code (e.g., 'NOT_FOUND')
  }
}

Types

import type {
  CodmirClientConfig,
  CodmirApiError,
  User,
  Project,
  Ticket,
  TestCase,
  AgentTask,
  CreateProjectInput,
  CreateTicketInput,
  UpdateTicketInput,
  CreateTestCaseInput,
  CreateAgentTaskInput,
  TicketStatus,
  TicketPriority,
} from '@codmir/sdk';