Samples
Basic text generation
Generate a simple response:Multi-turn conversation
Continue a conversation with message history:Use a system prompt
Guide Claude’s behavior:Control creativity with temperature
Adjust the randomness of responses:Use tools (function calling)
Enable Claude to call functions:Control stop sequences
Stop generation at specific sequences:Use with API key name
Reference a stored API key:Arguments
Returns
JSONB: The complete API response including:
id: Unique message identifiertype: Response type (always"message")role: Role of the responder (always"assistant")content: Array of content blocks (text, tool use, etc.)model: Model used for generationstop_reason: Why generation stopped (e.g.,"end_turn","max_tokens")usage: Token usage statistics
Related functions
anthropic_list_models(): list available Claude modelsopenai_chat_complete(): alternative with OpenAI models