Organizations API

Quick Access: Organizations

The Organizations API allows you to create and manage organizations, invite members, and configure shared resources.

Endpoints Overview

Endpoint Method Description
/api/organizations GET List your organizations
/api/organizations POST Create organization
/api/organizations/{id} GET Get organization details
/api/organizations/{id} PUT Update organization
/api/organizations/{id}/members GET List members
/api/organizations/{id}/members/invite POST Invite member
/api/organizations/{id}/members/{user_id} PUT Update member
/api/organizations/{id}/members/{user_id} DELETE Remove member

List Organizations

Get all organizations you belong to.

Endpoint

GET /api/organizations

Example Request

curl https://api.langmart.ai/api/organizations \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "organizations": [
    {
      "id": "org_abc123",
      "name": "Acme Corp",
      "slug": "acme-corp",
      "role": "admin",
      "member_count": 15,
      "is_primary": true,
      "created_at": "2025-01-01T00:00:00Z"
    },
    {
      "id": "org_xyz789",
      "name": "Research Lab",
      "slug": "research-lab",
      "role": "member",
      "member_count": 8,
      "is_primary": false,
      "created_at": "2025-01-05T00:00:00Z"
    }
  ]
}

Create Organization

Create a new organization.

Endpoint

POST /api/organizations

Request Body

Field Type Required Description
name string Yes Organization name
slug string No URL slug (auto-generated if not provided)
description string No Organization description
website string No Organization website
is_public boolean No Allow public join requests

Example Request

curl -X POST https://api.langmart.ai/api/organizations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Team",
    "description": "AI research team",
    "is_public": false
  }'

Response

{
  "id": "org_new123",
  "name": "My Team",
  "slug": "my-team",
  "description": "AI research team",
  "role": "owner",
  "is_public": false,
  "created_at": "2025-01-10T12:00:00Z"
}

Get Organization Details

Get detailed information about an organization.

Endpoint

GET /api/organizations/{org_id}

Response

{
  "id": "org_abc123",
  "name": "Acme Corp",
  "slug": "acme-corp",
  "description": "Enterprise AI solutions",
  "website": "https://acme.com",
  "is_public": true,
  "member_count": 15,
  "connection_count": 5,
  "settings": {
    "default_billing_mode": "org_paid",
    "auto_approve_requests": false,
    "require_2fa": false
  },
  "created_at": "2025-01-01T00:00:00Z",
  "updated_at": "2025-01-10T00:00:00Z"
}

Update Organization

Update organization settings.

Endpoint

PUT /api/organizations/{org_id}

Example

curl -X PUT https://api.langmart.ai/api/organizations/org_abc123 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme Corporation",
    "is_public": true
  }'

List Members

Get all members of an organization.

Endpoint

GET /api/organizations/{org_id}/members

Response

{
  "members": [
    {
      "user_id": "user_abc123",
      "email": "[email protected]",
      "name": "John Admin",
      "role": "owner",
      "status": "active",
      "joined_at": "2025-01-01T00:00:00Z"
    },
    {
      "user_id": "user_xyz789",
      "email": "[email protected]",
      "name": "Jane Developer",
      "role": "member",
      "status": "active",
      "joined_at": "2025-01-05T00:00:00Z"
    }
  ],
  "pagination": {
    "total": 15,
    "limit": 50,
    "offset": 0
  }
}

Invite Member

Invite a new member to the organization.

Endpoint

POST /api/organizations/{org_id}/members/invite

Request Body

Field Type Required Description
email string Yes Member email
role string No Role: member, admin (default: member)
message string No Custom invitation message

Example

curl -X POST https://api.langmart.ai/api/organizations/org_abc123/members/invite \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "role": "member",
    "message": "Welcome to our AI team!"
  }'

Response

{
  "invitation_id": "inv_abc123",
  "email": "[email protected]",
  "role": "member",
  "status": "pending",
  "expires_at": "2025-01-17T12:00:00Z",
  "created_at": "2025-01-10T12:00:00Z"
}

Update Member Role

Change a member's role in the organization.

Endpoint

PUT /api/organizations/{org_id}/members/{user_id}

Request Body

{
  "role": "admin"
}

Roles

Role Permissions
owner Full control, cannot be removed
admin Manage members, connections, billing
member Use models, view analytics

Remove Member

Remove a member from the organization.

Endpoint

DELETE /api/organizations/{org_id}/members/{user_id}

Example

curl -X DELETE https://api.langmart.ai/api/organizations/org_abc123/members/user_xyz789 \
  -H "Authorization: Bearer YOUR_API_KEY"

Accept Invitation

Accept an organization invitation.

Endpoint

POST /api/organizations/invitations/accept

Request Body

{
  "token": "invitation_token_here"
}

Organization Usage

Get usage statistics for the organization.

Endpoint

GET /api/organizations/{org_id}/usage

Query Parameters

Parameter Type Description
start_date string Start date (ISO 8601)
end_date string End date (ISO 8601)
group_by string day, member, model

Response

{
  "total_cost": 1250.50,
  "total_tokens": 25000000,
  "total_requests": 15420,
  "by_member": [
    {
      "user_id": "user_abc123",
      "name": "John Admin",
      "cost": 500.25,
      "requests": 5000
    }
  ],
  "by_model": [
    {
      "model": "openai/gpt-4o",
      "cost": 800.00,
      "requests": 8000
    }
  ]
}

Set Spending Limits

Configure per-member spending limits.

Endpoint

PUT /api/organizations/{org_id}/spending-limits

Request Body

{
  "default_daily_limit": 50.00,
  "default_monthly_limit": 500.00,
  "member_limits": {
    "user_xyz789": {
      "daily_limit": 25.00,
      "monthly_limit": 250.00
    }
  }
}

Python Example

import requests

API_KEY = "your-api-key"
BASE_URL = "https://api.langmart.ai"

def list_organizations():
    response = requests.get(
        f"{BASE_URL}/api/organizations",
        headers={"Authorization": f"Bearer {API_KEY}"}
    )
    return response.json()

def create_organization(name, description=None):
    response = requests.post(
        f"{BASE_URL}/api/organizations",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"name": name, "description": description}
    )
    return response.json()

def invite_member(org_id, email, role="member"):
    response = requests.post(
        f"{BASE_URL}/api/organizations/{org_id}/members/invite",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"email": email, "role": role}
    )
    return response.json()

def get_organization_usage(org_id, start_date):
    response = requests.get(
        f"{BASE_URL}/api/organizations/{org_id}/usage",
        headers={"Authorization": f"Bearer {API_KEY}"},
        params={"start_date": start_date, "group_by": "member"}
    )
    return response.json()

# List organizations
orgs = list_organizations()
for org in orgs["organizations"]:
    print(f"{org['name']} ({org['role']}): {org['member_count']} members")

# Create new organization
new_org = create_organization("AI Research Team", "Our AI research group")
print(f"Created: {new_org['name']} (ID: {new_org['id']})")

# Invite team members
invite_member(new_org["id"], "[email protected]", "member")
invite_member(new_org["id"], "[email protected]", "admin")

# Check usage
usage = get_organization_usage(new_org["id"], "2025-01-01")
print(f"Total cost: ${usage['total_cost']:.2f}")