Chain API call cascade, pass second value as third call argument, "id is not a valid integer"
so you are trying to fetch the details of contacts that are related to the ones you search for first?
The $value refers to the last call in a nested one. 

$result = civicrm_api3('Contact', 'get', array(
  'sequential' =&gt; 1,
  'return' =&gt; "id",
  'api.Relationship.get' 
   =&gt; array(
     'contact_id_a' =&gt; "\$value.id",
     'api.contact.get' =&gt; "\$value.contact_id_b"),
));


If you want to give more params to the inner api.contact.get:

$result = civicrm_api3('Contact', 'get', array(
  'sequential' =&gt; 1,
  'return' =&gt; "id",
  'api.Relationship.get' 
   =&gt; array('contact_id_a' =&gt; "\$value.id", 
     'api.contact.get' 
      =&gt; array(
        'id' =&gt; "\$value.contact_id_b", 
        'sequential' =&gt; 1, 
        'return' =&gt; "display_name"
      )
    ),
  )
);