ArmorIQ LogoArmorIQ SDK

Token expired

Refresh the token before invoking an action.

Token expired

Cause: Token validity period elapsed.

Solution:

import time

def invoke_with_auto_refresh(client, llm, prompt, mcp, action, params):
    captured = client.capture_plan(llm=llm, prompt=prompt)
    token_response = client.get_intent_token(captured)
    token = token_response["token"]
    expires_at = token_response["expires_at"]

    # Check if token expired
    if time.time() >= expires_at:
        # Get fresh token
        token_response = client.get_intent_token(captured)
        token = token_response["token"]

    return client.invoke(mcp, action, token, params)
import { ArmorIQClient, IntentToken, PlanCapture } from '@armoriq/sdk';

async function invokeWithAutoRefresh(
  client: ArmorIQClient,
  planCapture: PlanCapture,
  token: IntentToken,
  mcp: string,
  action: string,
  params: Record<string, any>
) {
  // Check if token expired or expiring soon
  if (IntentToken.isExpired(token) || IntentToken.timeUntilExpiry(token) < 30) {
    // Get fresh token
    console.log('Token expired or expiring soon, refreshing...');
    token = await client.getIntentToken(planCapture);
  }

  return await client.invoke(mcp, action, token, params);
}

// Usage
const plan = { steps: [{ action: 'analyze', mcp: 'analytics-mcp' }] };
const planCapture = client.capturePlan('gpt-4', 'Analyze data', plan);
let token = await client.getIntentToken(planCapture);

// Later, check before invoking
const result = await invokeWithAutoRefresh(
  client,
  planCapture,
  token,
  'analytics-mcp',
  'analyze',
  { data: [1, 2, 3] }
);

On this page