> ## Documentation Index
> Fetch the complete documentation index at: https://docs.electronhub.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Messages API

> Create messages using Anthropic-style format

The Messages API provides Anthropic-style message creation for Claude models.

## Create Message

`POST /messages`

Create a message completion using Anthropic's message format.

### Request Body

<ParamField body="model" type="string" required>
  The model to use for completion (e.g., "claude-3-sonnet-20240229")
</ParamField>

<ParamField body="messages" type="array" required>
  An array of message objects
</ParamField>

<ParamField body="max_tokens" type="integer" required>
  Maximum number of tokens to generate
</ParamField>

<ParamField body="temperature" type="number">
  Temperature for randomness (0.0 to 1.0)
</ParamField>

<ParamField body="system" type="string">
  System message to set context
</ParamField>

### Response

Returns a message completion object with the generated response.

### Example

<CodeGroup>
  ```javascript Node.js theme={null}
  const response = await fetch('https://api.electronhub.ai/v1/messages', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'claude-3-sonnet-20240229',
      max_tokens: 1000,
      messages: [
        { role: 'user', content: 'Hello, Claude!' }
      ]
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.electronhub.ai/v1/messages',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'model': 'claude-3-sonnet-20240229',
          'max_tokens': 1000,
          'messages': [
              {'role': 'user', 'content': 'Hello, Claude!'}
          ]
      }
  )

  print(response.json())
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.electronhub.ai/v1/messages" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "claude-3-sonnet-20240229",
      "max_tokens": 1000,
      "messages": [
        {"role": "user", "content": "Hello, Claude!"}
      ]
    }'
  ```
</CodeGroup>


## OpenAPI

````yaml POST /messages
openapi: 3.0.1
info:
  title: Electron Hub API
  description: >-
    Unified API platform integrating 200+ AI models for chat, image generation,
    speech-to-text, embeddings, and more.
  version: 1.0.0
  contact:
    name: Electron Hub Support
    email: support@electronhub.ai
    url: https://discord.com/invite/electronhub
  license:
    name: MIT
servers:
  - url: https://api.electronhub.ai/v1
    description: Production API v1
security:
  - bearerAuth: []
paths:
  /messages:
    post:
      summary: Create Message (Anthropic)
      description: Create a message using Anthropic format
      operationId: createMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessageRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageResponse'
components:
  schemas:
    MessageRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          example: claude-3-5-sonnet-20241022
        messages:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicMessage'
        max_tokens:
          type: integer
          description: Maximum tokens to generate
        temperature:
          type: number
          minimum: 0
          maximum: 1
        top_p:
          type: number
        top_k:
          type: integer
        stream:
          type: boolean
          default: false
        system:
          type: string
          description: System prompt
        tools:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicTool'
        tool_choice:
          $ref: '#/components/schemas/AnthropicToolChoice'
        thinking:
          $ref: '#/components/schemas/ThinkingConfig'
        reasoning_effort:
          type: string
          enum:
            - none
            - minimal
            - low
            - medium
            - high
            - xhigh
          description: >-
            Reasoning effort level. Silently ignored for models that do not
            support reasoning_effort.
    MessageResponse:
      type: object
      required:
        - id
        - type
        - role
        - content
        - model
        - stop_reason
        - usage
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - message
        role:
          type: string
          enum:
            - assistant
        content:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicContentPart'
        model:
          type: string
        stop_reason:
          type: string
          enum:
            - end_turn
            - max_tokens
            - stop_sequence
            - tool_use
          nullable: true
        stop_sequence:
          type: string
          nullable: true
        usage:
          $ref: '#/components/schemas/AnthropicUsage'
    AnthropicMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/AnthropicContentPart'
    AnthropicTool:
      type: object
      required:
        - name
        - input_schema
      properties:
        name:
          type: string
        description:
          type: string
        input_schema:
          type: object
    AnthropicToolChoice:
      oneOf:
        - type: string
          enum:
            - auto
            - any
        - type: object
          required:
            - type
            - name
          properties:
            type:
              type: string
              enum:
                - tool
            name:
              type: string
    ThinkingConfig:
      type: object
      required:
        - type
        - budget_tokens
      properties:
        type:
          type: string
          enum:
            - enabled
        budget_tokens:
          type: integer
          description: Token budget for thinking
    AnthropicContentPart:
      oneOf:
        - $ref: '#/components/schemas/AnthropicTextContent'
        - $ref: '#/components/schemas/AnthropicImageContent'
        - $ref: '#/components/schemas/AnthropicToolUseContent'
        - $ref: '#/components/schemas/AnthropicToolResultContent'
    AnthropicUsage:
      type: object
      required:
        - input_tokens
        - output_tokens
      properties:
        input_tokens:
          type: integer
        output_tokens:
          type: integer
    AnthropicTextContent:
      type: object
      required:
        - type
        - text
      properties:
        type:
          type: string
          enum:
            - text
        text:
          type: string
    AnthropicImageContent:
      type: object
      required:
        - type
        - source
      properties:
        type:
          type: string
          enum:
            - image
        source:
          $ref: '#/components/schemas/AnthropicImageSource'
    AnthropicToolUseContent:
      type: object
      required:
        - type
        - id
        - name
        - input
      properties:
        type:
          type: string
          enum:
            - tool_use
        id:
          type: string
        name:
          type: string
        input:
          type: object
    AnthropicToolResultContent:
      type: object
      required:
        - type
        - tool_use_id
      properties:
        type:
          type: string
          enum:
            - tool_result
        tool_use_id:
          type: string
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/AnthropicContentPart'
        is_error:
          type: boolean
          default: false
    AnthropicImageSource:
      type: object
      required:
        - type
        - media_type
        - data
      properties:
        type:
          type: string
          enum:
            - base64
        media_type:
          type: string
          example: image/jpeg
        data:
          type: string
          description: Base64 encoded image data
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your API key (starts with 'ek-')

````