Skip to content

SDKs & Code Examples

Code examples for integrating AG2Trust into your applications.

Official SDKs

Coming soon - Official SDKs for Python, JavaScript, and Go.

For now, use the REST API directly with your preferred HTTP client.

Quick Examples

Send a Message

import requests

response = requests.post(
    "https://agents.ag2trust.com/api/v1/ask/support",
    headers={
        "X-API-Key": "cust_your_api_key",
        "Content-Type": "application/json"
    },
    json={"content": "Hello, I need help"}
)
print(response.json()["content"])
const response = await fetch(
  'https://agents.ag2trust.com/api/v1/ask/support',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'cust_your_api_key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ content: 'Hello, I need help' })
  }
);
const data = await response.json();
console.log(data.content);
curl -X POST https://agents.ag2trust.com/api/v1/ask/support \
  -H "X-API-Key: cust_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"content": "Hello, I need help"}'

Detailed Examples

Common Patterns

Conversation Threading

# First message
response1 = send_message("What's the weather?")
thread_id = response1["thread_id"]

# Follow-up (maintains context)
response2 = send_message("How about tomorrow?", thread_id=thread_id)

Error Handling

try:
    response = send_message("Hello")
except RateLimitError:
    time.sleep(retry_after)
    response = send_message("Hello")
except AgentUnavailableError:
    notify_user("Please try again later")

Async with Webhooks

# Send async request
callback = send_async_message(
    message="Analyze this data...",
    webhook_url="https://your-server.com/webhook"
)

# Response delivered to webhook later