how to programmatically set a group audience
First in your .install when creating your content type, add:

og_create_field(OG_AUDIENCE_FIELD, 'node', 'bundle_name_of_your_content_type');


Then when you need to assign a fresh new content of your content type to an existing group, you can do it in two ways:

1) Found it http://drupal.org/node/1249396#comment-4885442 and thanks to tenken

$node = node_load($nid);  
$values = array(  
  'entity type' =&gt; 'node',  
  'entity' =&gt; $node, 
  'state' =&gt; OG_STATE_ACTIVE);
og_group($gid, $values);
node_save($node);


2) Maybe less sexy

$node = node_load($nid);
$node-&gt;group_audience['und'][0] = array(
  'gid' =&gt; $gid, 
  'state' =&gt; OG_STATE_ACTIVE, 
  'created' =&gt; mktime());
node_save($node);


Cheers