Connections API

Quick Access: Manage Connections

The Connections API allows you to manage provider connections - the API keys that link LangMart to AI providers like OpenAI, Anthropic, and others.

Endpoints Overview

Endpoint Method Description
/api/connections GET List connections
/api/connections POST Create connection
/api/connections/{id} PUT Update connection
/api/connections/{id} DELETE Delete connection
/api/connections/{id}/test POST Test connection

List Connections

Get all your provider connections.

Endpoint

GET /api/connections

Example Request

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

Response

{
  "connections": [
    {
      "id": "conn_abc123",
      "name": "My OpenAI Key",
      "provider": "openai",
      "gateway_type": 2,
      "status": "active",
      "is_default": true,
      "last_tested_at": "2025-01-10T12:00:00Z",
      "created_at": "2025-01-01T00:00:00Z"
    },
    {
      "id": "conn_xyz789",
      "name": "Anthropic Production",
      "provider": "anthropic",
      "gateway_type": 2,
      "status": "active",
      "is_default": false,
      "last_tested_at": "2025-01-10T11:00:00Z",
      "created_at": "2025-01-05T00:00:00Z"
    }
  ]
}

Create Connection

Add a new provider connection.

Endpoint

POST /api/connections

Request Body

Field Type Required Description
name string Yes Connection name
provider string Yes Provider key (e.g., openai)
api_key string Yes Provider API key
endpoint_url string No Custom endpoint URL
gateway_type integer No Gateway type (2=cloud, 3=self-hosted)
is_default boolean No Set as default for provider

Example Request

curl -X POST https://api.langmart.ai/api/connections \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "OpenAI Production",
    "provider": "openai",
    "api_key": "sk-openai-key-here",
    "is_default": true
  }'

Response

{
  "id": "conn_new123",
  "name": "OpenAI Production",
  "provider": "openai",
  "gateway_type": 2,
  "status": "active",
  "is_default": true,
  "created_at": "2025-01-10T12:00:00Z"
}

Update Connection

Update an existing connection.

Endpoint

PUT /api/connections/{connection_id}

Request Body

{
  "name": "OpenAI Production (Updated)",
  "is_default": true
}

Example

curl -X PUT https://api.langmart.ai/api/connections/conn_abc123 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "OpenAI Primary"}'

Update API Key

Update the API key for a connection.

Endpoint

POST /api/connections/{connection_id}/update-key

Request Body

{
  "api_key": "sk-new-api-key-here"
}

Example

curl -X POST https://api.langmart.ai/api/connections/conn_abc123/update-key \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"api_key": "sk-new-openai-key"}'

Test Connection

Verify a connection is working.

Endpoint

POST /api/connections/{connection_id}/test

Example Request

curl -X POST https://api.langmart.ai/api/connections/conn_abc123/test \
  -H "Authorization: Bearer YOUR_API_KEY"

Response (Success)

{
  "success": true,
  "latency_ms": 245,
  "models_available": 15,
  "tested_at": "2025-01-10T12:00:00Z"
}

Response (Failure)

{
  "success": false,
  "error": "Invalid API key",
  "tested_at": "2025-01-10T12:00:00Z"
}

Delete Connection

Remove a connection.

Endpoint

DELETE /api/connections/{connection_id}

Example

curl -X DELETE https://api.langmart.ai/api/connections/conn_abc123 \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "success": true,
  "message": "Connection deleted"
}

Supported Providers

Provider Key Documentation
OpenAI openai platform.openai.com
Anthropic anthropic console.anthropic.com
Google google aistudio.google.com
Groq groq console.groq.com
Mistral mistral console.mistral.ai
Together together api.together.xyz
OpenRouter openrouter openrouter.ai
Baidu Qianfan (intl) qianfan intl.cloud.baidu.com — key format bce-v3/ALTAK-…/…

Connection Types

Gateway Type 2 (Cloud)

Your API keys are stored encrypted in LangMart:

{
  "gateway_type": 2,
  "description": "Keys stored in LangMart cloud"
}

Best for: Most users, quick setup.

Gateway Type 3 (Self-Hosted)

Your API keys stay on your infrastructure:

{
  "gateway_type": 3,
  "description": "Keys stored in your local vault"
}

Best for: Enterprise, compliance requirements.


Python Example

import requests

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

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

def create_connection(name, provider, provider_api_key):
    response = requests.post(
        f"{BASE_URL}/api/connections",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={
            "name": name,
            "provider": provider,
            "api_key": provider_api_key
        }
    )
    return response.json()

def test_connection(connection_id):
    response = requests.post(
        f"{BASE_URL}/api/connections/{connection_id}/test",
        headers={"Authorization": f"Bearer {API_KEY}"}
    )
    return response.json()

# List all connections
connections = list_connections()
for conn in connections["connections"]:
    print(f"{conn['name']} ({conn['provider']}): {conn['status']}")

# Create new connection
new_conn = create_connection(
    name="My Groq Key",
    provider="groq",
    provider_api_key="gsk_..."
)
print(f"Created: {new_conn['id']}")

# Test it
result = test_connection(new_conn["id"])
if result["success"]:
    print(f"Connection works! Latency: {result['latency_ms']}ms")
else:
    print(f"Connection failed: {result['error']}")