Conjure.API (Conjure v0.1.1-alpha)
View SourceHelpers for Claude API integration.
This module provides utilities for building API requests and parsing responses. It does not make HTTP calls - use your preferred HTTP client.
Example
# Build request components
system_prompt = Conjure.API.build_system_prompt("You are helpful.", skills)
tools = Conjure.API.build_tools_param(skills)
# Make API call with your client
response = MyApp.Claude.call(%{
model: "claude-sonnet-4-5-20250929",
system: system_prompt,
messages: messages,
tools: tools
})
# Parse response
{:ok, parsed} = Conjure.API.parse_response(response)
Summary
Functions
Build a complete messages array for an API request.
Build the system prompt with skills fragment appended.
Build the tools array for the API request.
Check if the response is an end_turn (conversation complete).
Estimate token count for a request.
Extract the full text content from a response.
Format tool results for the next API request.
Parse content blocks from an API response.
Check if a response requires tool execution.
Types
@type parsed_response() :: %{ text_blocks: [String.t()], tool_uses: [Conjure.ToolCall.t()], stop_reason: String.t() | nil, usage: map() | nil }
Functions
Build a complete messages array for an API request.
Handles the conversation history format expected by Claude.
@spec build_system_prompt(String.t(), [Conjure.Skill.t()], keyword()) :: String.t()
Build the system prompt with skills fragment appended.
Options
:include_instructions- Include skill usage instructions (default: true)
@spec build_tools_param( [Conjure.Skill.t()], keyword() ) :: [map()]
Build the tools array for the API request.
Options
:only- Only include these tool names:except- Exclude these tool names
Check if the response is an end_turn (conversation complete).
@spec estimate_tokens(String.t() | map()) :: pos_integer()
Estimate token count for a request.
This is a rough estimate assuming ~4 characters per token.
Extract the full text content from a response.
@spec format_tool_results_message([Conjure.ToolResult.t()]) :: map()
Format tool results for the next API request.
Returns a message map with role "user" and tool_result content blocks.
@spec parse_response(map()) :: {:ok, parsed_response()} | {:error, term()}
Parse content blocks from an API response.
Extracts text blocks, tool uses, and metadata from the response.
Check if a response requires tool execution.