WebSim AI Chat Assistant API

Welcome to the WebSim AI Chat Assistant API documentation. This API allows you to interact with our advanced AI assistant to enhance your web simulation experiences.

Authentication

All API requests require authentication using a bearer token. Include the following header in your requests:

Authorization: Bearer YOUR_API_TOKEN

Endpoints

POST /chat

Start a new chat session or continue an existing one with the AI assistant.

Request Body:

{
  "message": "Your message here",
  "session_id": "optional_session_id",
  "context": {
    "current_url": "https://example.com",
    "user_role": "developer"
  }
}
    

Response:

{
  "response": "AI assistant's response",
  "session_id": "generated_or_provided_session_id",
  "suggested_actions": [
    {
      "type": "navigate",
      "url": "https://example.com/suggested-page"
    },
    {
      "type": "modify_dom",
      "selector": "#main-content",
      "action": "append",
      "content": "

Suggested content

" } ] }

GET /sessions/{session_id}

Retrieve the chat history for a specific session.

Response:

{
  "session_id": "requested_session_id",
  "messages": [
    {
      "role": "user",
      "content": "User message"
    },
    {
      "role": "assistant",
      "content": "AI response"
    }
  ]
}
    

DELETE /sessions/{session_id}

End a chat session and delete its history.

Response:

{
  "status": "success",
  "message": "Session deleted successfully"
}
    

WebSim Integration

The WebSim AI Chat Assistant is designed to enhance your web simulation experiences. It can provide contextual assistance, suggest modifications to the simulated web environment, and even generate new content on the fly.

Example Usage

Here's an example of how you might use the Chat Assistant API in a WebSim scenario:

// Request
POST /chat
{
  "message": "Can you help me add a navigation menu to this page?",
  "context": {
    "current_url": "https://websim.ai/c/example-site",
    "user_role": "designer"
  }
}

// Response
{
  "response": "Certainly! I'd be happy to help you add a navigation menu to your page. Here's a suggestion for a simple navigation menu structure:",
  "session_id": "abc123",
  "suggested_actions": [
    {
      "type": "modify_dom",
      "selector": "body",
      "action": "prepend",
      "content": ""
    },
    {
      "type": "add_css",
      "content": "nav { background-color: #333; } nav ul { list-style-type: none; padding: 0; } nav ul li { display: inline; margin-right: 10px; } nav ul li a { color: white; text-decoration: none; }"
    }
  ]
}
  

In this example, the AI assistant not only provides a textual response but also suggests specific actions to modify the DOM and add CSS, directly enhancing the simulated web page.

Rate Limiting

To ensure fair usage, API calls are rate-limited to 60 requests per minute per API token. If you exceed this limit, you'll receive a 429 Too Many Requests response.

Error Handling

The API uses standard HTTP response codes. In case of an error, you'll receive a JSON response with an "error" key explaining the issue.