Skip to main content

Error Types

The SDK throws specific errors for different conditions:
import Reminix from '@reminix/sdk';
import {
  ReminixError,          // Base error class
  AuthenticationError,   // 401 - Invalid API key
  NotFoundError,         // 404 - Agent not found
  BadRequestError,       // 400 - Invalid request
  GatewayError,          // 502 - Agent unreachable
  TimeoutError,          // 504 - Agent timeout
  APIError               // Other API errors
} from '@reminix/sdk';

Basic Error Handling

import Reminix from '@reminix/sdk';
import { ReminixError, AuthenticationError, NotFoundError } from '@reminix/sdk';

const client = new Reminix();

try {
  const response = await client.agents.invoke('my-agent', {
    prompt: 'Analyze this data'
  });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error(`Invalid API key: ${error.message}`);
  } else if (error instanceof NotFoundError) {
    console.error(`Agent not found: ${error.message}`);
  } else if (error instanceof ReminixError) {
    console.error(`API error: ${error.message}`);
  } else {
    throw error;
  }
}

Authentication Errors

Thrown when the API key is invalid or missing:
import { AuthenticationError } from '@reminix/sdk';

try {
  const client = new Reminix({ apiKey: 'invalid_key' });
  await client.project.retrieve();
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error(`Authentication failed: ${error.message}`);
    console.error(`Status code: ${error.status}`);  // 401
  }
}

Not Found Errors

Thrown when the agent or deployment doesn’t exist:
import { NotFoundError } from '@reminix/sdk';

try {
  const response = await client.agents.invoke('nonexistent-agent', {
    prompt: 'hello'
  });
} catch (error) {
  if (error instanceof NotFoundError) {
    console.error(`Agent not found: ${error.message}`);
    // "No ready deployment found for this project"
  }
}

Gateway Errors

Thrown when the agent machine is unreachable:
import { GatewayError } from '@reminix/sdk';

try {
  const response = await client.agents.invoke('my-agent', { prompt: 'hello' });
} catch (error) {
  if (error instanceof GatewayError) {
    console.error(`Agent unreachable: ${error.message}`);
    // "Unable to reach agent machine. The deployment may be down."
  }
}

Timeout Errors

Thrown when the agent takes too long to respond (>60 seconds):
import { TimeoutError } from '@reminix/sdk';

try {
  const response = await client.agents.invoke('slow-agent', {
    prompt: 'long operation'
  });
} catch (error) {
  if (error instanceof TimeoutError) {
    console.error(`Agent timeout: ${error.message}`);
    // "Request timeout - agent took too long to respond"
    
    // Use streaming to avoid timeouts
    const stream = await client.agents.invoke('slow-agent', {
      prompt: 'long operation',
      stream: true
    });
    for await (const chunk of stream) {
      process.stdout.write(chunk);
    }
  }
}

Bad Request Errors

Thrown when the request is malformed:
import { BadRequestError } from '@reminix/sdk';

try {
  // Invalid agent name
  const response = await client.agents.invoke('invalid name!', { prompt: 'hello' });
} catch (error) {
  if (error instanceof BadRequestError) {
    console.error(`Invalid request: ${error.message}`);
    // "Agent name must be URL-safe (alphanumeric, hyphens, underscores only)"
  }
}

Full Example

import Reminix from '@reminix/sdk';
import {
  AuthenticationError,
  NotFoundError,
  GatewayError,
  TimeoutError,
  BadRequestError,
  ReminixError
} from '@reminix/sdk';

async function safeExecute(
  client: Reminix,
  agent: string,
  params: Record<string, unknown>,
  retries = 3
): Promise<unknown> {
  
  for (let attempt = 0; attempt < retries; attempt++) {
    try {
      const response = await client.agents.invoke(agent, params);
      return response.content;
      
    } catch (error) {
      if (error instanceof GatewayError) {
        // Agent might be restarting, retry
        if (attempt < retries - 1) {
          console.log(`Agent unreachable, retrying in ${2 ** attempt}s...`);
          await new Promise(r => setTimeout(r, 2 ** attempt * 1000));
          continue;
        }
        throw error;
      }
      
      if (error instanceof TimeoutError) {
        // Try streaming instead
        console.log('Request timed out, trying streaming...');
        const chunks: string[] = [];
        const stream = await client.agents.invoke(agent, { ...params, stream: true });
        for await (const chunk of stream) {
          chunks.push(chunk);
        }
        return chunks.join('');
      }
      
      if (error instanceof AuthenticationError) {
        throw error;  // Don't retry auth errors
      }
      
      if (error instanceof NotFoundError) {
        throw error;  // Don't retry - agent doesn't exist
      }
      
      if (error instanceof ReminixError) {
        if (attempt < retries - 1) {
          console.log(`API error, retrying: ${error.message}`);
          await new Promise(r => setTimeout(r, 2 ** attempt * 1000));
          continue;
        }
        throw error;
      }
      
      throw error;
    }
  }
  
  throw new Error('Max retries exceeded');
}

// Usage
const client = new Reminix();

try {
  const result = await safeExecute(client, 'my-agent', { prompt: 'Analyze this' });
  console.log(`Result: ${result}`);
  
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Check your API key');
  } else if (error instanceof NotFoundError) {
    console.error("Agent doesn't exist - check the name or deploy it first");
  } else if (error instanceof GatewayError) {
    console.error('Agent is down - check the deployment status');
  } else if (error instanceof ReminixError) {
    console.error(`Unexpected error: ${error.message}`);
  }
}

Streaming Error Handling

Handle errors during streaming:
try {
  const stream = await client.agents.invoke('my-agent', {
    prompt: 'hello',
    stream: true
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk);
  }
} catch (error) {
  if (error instanceof ReminixError) {
    console.error(`\nStream error: ${error.message}`);
    // You may have received partial content before the error
  }
}