> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://humanloop.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://humanloop.com/docs/_mcp/server.

# Log

POST https://api.humanloop.com/v4/logs
Content-Type: application/json

Log a datapoint or array of datapoints to your Humanloop project.

Reference: https://humanloop.com/docs/v4/api/logs/log

## Authentication

- `X-API-KEY` header (required) — API Key authentication via header

## Request

### Body (application/json)

This endpoint expects a LogsLogRequest.

- `LogsLogRequest`

## Response

### 200

Successful Response

- `LogsLogResponse`

## Errors

### 422 Logs Log Request Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### LogRequest

Request model for logging a datapoint.

- `project` (string, optional) — Unique project name. If no project exists with this name, a new project will be created.
- `project_id` (string, optional) — Unique ID of a project to associate to the log. Either this or `project` must be provided.
- `session_id` (string, optional) — ID of the session to associate the datapoint.
- `session_reference_id` (string, optional) — A unique string identifying the session to associate the datapoint to. Allows you to log multiple datapoints to a session (using an ID kept by your internal systems) by passing the same `session_reference_id` in subsequent log requests. Specify at most one of this or `session_id`.
- `parent_id` (string, optional) — ID associated to the parent datapoint in a session.
- `parent_reference_id` (string, optional) — A unique string identifying the previously-logged parent datapoint in a session. Allows you to log nested datapoints with your internal system IDs by passing the same reference ID as `parent_id` in a prior log request. Specify at most one of this or `parent_id`. Note that this cannot refer to a datapoint being logged in the same request.
- `inputs` (map from string to any, optional) — The inputs passed to the prompt template.
- `source` (string, optional) — Identifies where the model was called from.
- `metadata` (map from string to any, optional) — Any additional metadata to record.
- `save` (boolean, optional, default: true) — Whether the request/response payloads will be stored on Humanloop.
- `source_datapoint_id` (string, optional) — ID of the source datapoint if this is a log derived from a datapoint in a dataset.
- `reference_id` (string, optional) — A unique string to reference the datapoint. Allows you to log nested datapoints with your internal system IDs by passing the same reference ID as `parent_id` in a subsequent log request.
- `messages` (list of ChatMessageWithToolCall, optional) — The messages passed to the to provider chat endpoint.
- `output` (string, optional) — Generated output from your model for the provided inputs. Can be `None` if logging an error, or if logging a parent datapoint with the intention to populate it later
- `judgment` (Judgment, optional)
- `config_id` (string, optional) — Unique ID of a config to associate to the log.
- `config` (Config, optional) — The model config used for this generation. Required unless `config_id` is provided.
- `environment` (string, optional) — The environment name used to create the log.
- `feedback` (LogRequestFeedback, optional) — Optional parameter to provide feedback with your logged datapoint.
- `created_at` (datetime, optional) — User defined timestamp for when the log was created.
- `error` (string, optional) — Error message if the log is an error.
- `stdout` (string, optional) — Captured log and debug statements.
- `duration` (double, optional) — Duration of the logged event in seconds.
- `output_message` (ChatMessageWithToolCall, optional) — The message returned by the provider.
- `prompt_tokens` (integer, optional) — Number of tokens in the prompt used to generate the output.
- `output_tokens` (integer, optional) — Number of tokens in the output generated by the model.
- `prompt_cost` (double, optional) — Cost in dollars associated to the tokens in the prompt.
- `output_cost` (double, optional) — Cost in dollars associated to the tokens in the output.
- `provider_request` (map from string to any, optional) — Raw request sent to provider.
- `provider_response` (map from string to any, optional) — Raw response received the provider.

### CreateLogResponse

- `id` (string, required) — String ID of logged datapoint. Starts with `data_`.
- `project_id` (string, required) — String ID of project the datapoint belongs to. Starts with `pr_`.
- `session_id` (string, optional) — String ID of session the datapoint belongs to. Populated only if the datapoint was logged with `session_id` or `session_reference_id`, and is `None` otherwise. Starts with `sesh_`.

### ValidationError

- `loc` (list of ValidationErrorLocItem, required)
- `msg` (string, required)
- `type` (string, required)

### ChatMessageWithToolCall

- `role` (enum, required) — Role of the message author.
  - Allowed values: `user`, `assistant`, `system`, `tool`, `developer`
- `content` (Content, optional) — The content of the message.
- `name` (string, optional) — Optional name of the message author.
- `tool_call_id` (string, optional) — Tool call that this message is responding to.
- `tool_calls` (list of ToolCall, optional) — A list of tool calls requested by the assistant.
- `thinking` (list of ChatMessageWithToolCallThinkingItem, optional) — Model's chain-of-thought for providing the response. Present on assistant messages if model supports it.
- `tool_call` (FunctionTool, optional, deprecated) — NB: Deprecated in favour of tool_calls. A tool call requested by the assistant.

### Judgment

### Config

The model config used for this generation. Required unless `config_id` is provided.

- `type`: `model`
  - `model` (string, required) — The model instance used. E.g. text-davinci-002.
  - `chat_template` (list of ChatMessageWithToolCall, optional) — Messages prepended to the list of messages sent to the provider. These messages that will take your specified inputs to form your final request to the provider model. Input variables within the template should be specified with syntax: `{{input_name}}`.
  - `description` (string, optional) — A description of the model config.
  - `endpoint` (enum, optional) — The provider model endpoint used.
    - Allowed values: `complete`, `chat`, `edit`
  - `frequency_penalty` (double, optional, default: 0) — Number between -2.0 and 2.0. Positive values penalize new tokens based on how frequently they appear in the generation so far.
  - `max_tokens` (integer, optional, default: -1) — The maximum number of tokens to generate. Provide max_tokens=-1 to dynamically calculate the maximum number of tokens to generate given the length of the prompt
  - `name` (string, optional) — A friendly display name for the model config. If not provided, a name will be generated.
  - `other` (map from string to any, optional) — Other parameter values to be passed to the provider call.
  - `presence_penalty` (double, optional, default: 0) — Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the generation so far.
  - `prompt_template` (string, optional) — Prompt template that will take your specified inputs to form your final request to the model. Input variables within the prompt template should be specified with syntax: `{{input_name}}`.
  - `provider` (enum, optional) — The company providing the underlying model service.
    - Allowed values: `anthropic`, `bedrock`, `cohere`, `deepseek`, `google`, `groq`, `mock`, `openai`, `openai_azure`, `replicate`
  - `reasoning_effort` (ModelConfigRequestReasoningEffort, optional) — Guidance on how many reasoning tokens it should generate before creating a response to the prompt. OpenAI reasoning models (o1, o3-mini) expect a OpenAIReasoningEffort enum. Anthropic reasoning models expect an integer, which signifies the maximum token budget.
  - `response_format` (ResponseFormat, optional) — The format of the response. Only type json_object is currently supported for chat.
  - `seed` (integer, optional) — If specified, model will make a best effort to sample deterministically, but it is not guaranteed.
  - `stop` (ModelConfigRequestStop, optional) — The string (or list of strings) after which the model will stop generating. The returned text will not contain the stop sequence.
  - `temperature` (double, optional, default: 1) — What sampling temperature to use when making a generation. Higher values means the model will be more creative.
  - `template_language` (enum, optional) — The template language to use for rendering the template.
    - Allowed values: `default`, `jinja`
  - `tools` (list of ModelConfigRequestToolsItem, optional) — Make tools available to OpenAIs chat model as functions.
  - `top_p` (double, optional, default: 1) — An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
- `type`: `tool`
  - `name` (string, required) — The name of the tool shown to the model.
  - `description` (string, optional) — The description of the tool shown to the model.
  - `other` (map from string to any, optional) — Other parameters that define the config.
  - `parameters` (map from string to any, optional) — Definition of parameters needed to run the tool. Provided in jsonschema format: https://json-schema.org/
  - `preset_name` (string, optional) — If is_preset = true, this is the name of the preset tool on Humanloop. This is used as the key to look up the Humanloop runtime of the tool
  - `source` (enum, optional) — Source of the tool. If defined at an organization level will be 'organization' else 'inline'.
    - Allowed values: `organization`, `inline`
  - `source_code` (string, optional) — Code source of the tool.
  - `strict` (boolean, optional) — Whether the tool is strict or not. If strict, the model will be forced to respond with JSON matching the parameters schema.

### LogRequestFeedback

Optional parameter to provide feedback with your logged datapoint.

### ValidationErrorLocItem

### Content

The content of the message.

### ToolCall

A tool call to be made.

- `id` (string, required)
- `type` ("function", required) — The type of tool to call.
- `function` (FunctionTool, required) — A function tool to be called by the model where user owns runtime.

### ChatMessageWithToolCallThinkingItem

- `type`: `thinking`
  - `signature` (string, required) — Cryptographic signature that verifies the thinking block was generated by Anthropic.
  - `thinking` (string, required) — Model's chain-of-thought for providing the response.
- `type`: `redacted_thinking`
  - `data` (string, required) — Thinking block Anthropic redacted for safety reasons. User is expected to pass the block back to Anthropic

### FunctionTool

A function tool to be called by the model where user owns runtime.

- `name` (string, required)
- `arguments` (string, optional)

### ModelConfigRequestReasoningEffort

Guidance on how many reasoning tokens it should generate before creating a response to the prompt. OpenAI reasoning models (o1, o3-mini) expect a OpenAIReasoningEffort enum. Anthropic reasoning models expect an integer, which signifies the maximum token budget.

### ResponseFormat

Response format of the model.

- `type` (enum, required)
  - Allowed values: `json_object`, `json_schema`
- `json_schema` (map from string to any, optional) — The JSON schema of the response format if type is json_schema.

### ModelConfigRequestStop

The string (or list of strings) after which the model will stop generating. The returned text will not contain the stop sequence.

### ModelConfigRequestToolsItem

### Feedback

- `type` (enum, required) — The type of feedback. The default feedback types available are 'rating', 'action', 'issue', 'correction', and 'comment'.
  - Allowed values: `rating`, `action`, `issue`, `correction`, `comment`
- `value` (FeedbackValue, optional) — The feedback value to set. This would be the appropriate text for 'correction' or 'comment', or a label to apply for 'rating', 'action', or 'issue'.
- `data_id` (string, optional) — ID to associate the feedback to a previously logged datapoint.
- `user` (string, optional) — A unique identifier to who provided the feedback.
- `created_at` (datetime, optional) — User defined timestamp for when the feedback was created.

### LinkedToolRequest

- `id` (string, required) — The ID of the linked tool. Starts with "oc_"
- `source` ("organization", required) — The source of the linked tool. For a linked tool it should be `organization`
- `name` (string, optional) — The name of the linked tool.
- `description` (string, optional) — The description of the linked tool.
- `strict` (boolean, optional) — Whether the tool is strict or not. If strict, the model will be forced to respond with JSON matching the parameters schema.
- `parameters` (map from string to any, optional) — The parameters of the linked tool.

### ModelConfigToolRequest

Definition of tool within a model config. The subset of ToolConfig parameters received by the chat endpoint. Does not have things like the signature or setup schema.

- `name` (string, required) — The name of the tool shown to the model.
- `description` (string, optional) — The description of the tool shown to the model.
- `strict` (boolean, optional) — Whether the tool is strict or not. If strict, the model will be forced to respond with JSON matching the parameters schema.
- `parameters` (map from string to any, optional) — Definition of parameters needed to run the tool. Provided in jsonschema format: https://json-schema.org/
- `source` (enum, optional) — Source of the tool. If defined at an organization level will be 'organization' else 'inline'.
  - Allowed values: `organization`, `inline`
- `source_code` (string, optional) — Code source of the tool.
- `other` (map from string to any, optional) — Other parameters that define the config.
- `preset_name` (string, optional) — If is_preset = true, this is the name of the preset tool on Humanloop. This is used as the key to look up the Humanloop runtime of the tool

### FeedbackValue

The feedback value to set. This would be the appropriate text for 'correction' or 'comment', or a label to apply for 'rating', 'action', or 'issue'.

## Examples

**Request**

```json
[
  {}
]
```

**Response**

```json
[
  {
    "id": "id",
    "project_id": "project_id",
    "session_id": "session_id"
  }
]
```

**SDK Code**

```python
import requests

url = "https://api.humanloop.com/v4/logs"

payload = [{}]
headers = {
    "X-API-KEY": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.humanloop.com/v4/logs';
const options = {
  method: 'POST',
  headers: {'X-API-KEY': '<apiKey>', 'Content-Type': 'application/json'},
  body: '[{}]'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.humanloop.com/v4/logs"

	payload := strings.NewReader("[\n  {}\n]")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-API-KEY", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.humanloop.com/v4/logs")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {}\n]"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.humanloop.com/v4/logs")
  .header("X-API-KEY", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("[\n  {}\n]")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.humanloop.com/v4/logs', [
  'body' => '[
  {}
]',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-KEY' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.humanloop.com/v4/logs");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-KEY", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {}\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-API-KEY": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [[]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.humanloop.com/v4/logs")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```