When to Use Custom Logging
Use thelog_request method when:
- You’re not using
pl_client.run()for executing prompts - You need more flexibility (e.g., background processing, custom models)
- You want to track requests made with your own LLM client code (OpenAI, Anthropic, etc.)
- You want to log requests from any LLM provider
run() method, it offers greater control over the logging process and supports any LLM provider.
API Reference
For complete documentation on thelog_request API, see the Log Request API Reference.
Request Parameters
When logging a custom request, you can use the following parameters (see API Reference for details):provider(required): The LLM provider name (e.g., “openai”, “anthropic”)model(required): The specific model used (e.g., “gpt-4o”, “claude-3-7-sonnet-20250219”)input(required): The input prompt in Prompt Blueprint formatoutput(required): The model response in Prompt Blueprint formatrequest_start_time: Timestamp when the request startedrequest_end_time: Timestamp when the response was receivedprompt_name: Name of the prompt template if using one from PromptLayerprompt_id: Unique identifier for the prompt templateprompt_version_number: Version number of the prompt templateprompt_input_variables: Variables used in the prompt templateinput_tokens: Number of input tokens usedoutput_tokens: Number of output tokens generatedtags: Array of strings for categorizing requestsmetadata: Custom JSON object for ability to search and filter requests laterapi_type: Api type to be used when working with openai/azure-openai (e.g, “chat-completions”, “responses”)
Basic Usage
Theinput and output must be in prompt blueprint format:
Provider Conversion Helpers
OpenAI Format Converter
Anthropic Format Converter
OpenAI Example
Anthropic Example
Logging Extended Thinking and Reasoning
When logging requests that use extended thinking (Anthropic), thinking mode (Google), or reasoning (OpenAI), you need to:- Include the thinking configuration in
parameters- Use the provider-specific format - Include thinking content blocks in the output - Add them to the message content array
Anthropic Extended Thinking
For Anthropic models with extended thinking enabled, pass thethinking parameter:
Google/Gemini Thinking Mode
For Google models with thinking mode, use thethinking_config parameter:
OpenAI Reasoning Models (o1, o3, etc.)
For OpenAI reasoning models, use thereasoning_effort parameter:
The parameter name varies by provider — make sure to use the correct format for your provider as shown above.
Working with Tools and Function Calls
For OpenAI/Anthropic function calling or tool use:Error Tracking
Usestatus, error_type, and error_message when logging failed or degraded requests. This keeps warnings and failures searchable in PromptLayer and makes provider reliability easier to monitor.
SUCCESSmeans the request completed normally.WARNINGmeans the request succeeded but had issues, such as retries or partial responses.ERRORmeans the provider call or prompt rendering failed.
error_type such as PROVIDER_TIMEOUT, PROVIDER_RATE_LIMIT, PROVIDER_AUTH_ERROR, TEMPLATE_RENDER_ERROR, or UNKNOWN_ERROR when possible, and include a short error_message with the provider or application detail.

