POST
/
chat
/
completions
curl --request POST \
  --url https://api.electronhub.ai/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "<string>",
      "name": "<string>",
      "tool_calls": [
        {
          "id": "<string>",
          "type": "function",
          "function": {
            "name": "<string>",
            "arguments": "<string>"
          }
        }
      ]
    }
  ],
  "stream": false,
  "max_tokens": 123,
  "temperature": 1,
  "top_p": 1,
  "top_k": 123,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "<string>",
        "description": "<string>",
        "parameters": {}
      }
    }
  ],
  "tool_choice": "none",
  "web_search": false,
  "thinking": {
    "type": "enabled",
    "budget_tokens": 123
  },
  "reasoning_effort": "low"
}'
{
  "id": "<string>",
  "object": "chat.completion",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "system",
        "content": "<string>",
        "name": "<string>",
        "tool_calls": [
          {
            "id": "<string>",
            "type": "function",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}

Create conversational AI responses using our chat completions endpoint.

Create Chat Completion

POST /chat/completions

Generate responses for conversational AI applications.

Request Body

model
string
required

Model to use for completion (e.g., “gpt-4”, “gpt-3.5-turbo”, “claude-3-sonnet-20240229”)

messages
array
required

Array of message objects forming the conversation

max_tokens
integer

Maximum number of tokens to generate

temperature
number

Sampling temperature between 0 and 2

stream
boolean

Enable streaming responses

Example

import requests

response = requests.post(
    'https://api.electronhub.ai/v1/chat/completions',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'model': 'gpt-3.5-turbo',
        'messages': [
            {'role': 'user', 'content': 'Hello!'}
        ]
    }
)

Streaming

Enable real-time responses with streaming:

curl https://api.electronhub.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {"role": "user", "content": "Tell me a story"}
    ],
    "stream": true
  }'

Function Calling

Use function calling for tool integration:

curl https://api.electronhub.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {"role": "user", "content": "What is the weather like in Boston?"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_current_weather",
          "description": "Get the current weather in a given location",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA"
              },
              "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
            },
            "required": ["location"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'

Authorizations

Authorization
string
header
required

Enter your API key (starts with 'ek-')

Body

application/json

Response

200 - application/json

Success

The response is of type object.