Skip to content

Anthropic

The UC AI Anthropic package integrates Anthropic’s Claude models into your Oracle database applications.

  • Support for the current Claude models (Fable, Opus, Sonnet, Haiku)
  • Full function calling (tools) support
  • Structured output (JSON schema-based responses)
  • Reasoning capabilities with Extended Thinking
  • Multi-modal support (text, images, PDFs)
  • Streaming responses
  1. Anthropic API key
  2. Oracle database with internet access to Anthropic’s API endpoints (see Network Setup (ACL & Wallet))
  3. UC AI package installed
  4. Set up API key (guide)

You can get an API key by signing up at Anthropic Console.

To use your Anthropic key with APEX Web Credentials, create a new web credential in your APEX workspace (Workspace Utilities → Web Credentials) with the following configuration:

  • Authentication Type: HTTP Header
  • Credential Name: x-api-key
  • Credential Secret: <your_api_key>

Also set Valid for URLs to the Anthropic API (https://api.anthropic.com/) to limit the scope of the credential.

To use the web credential in your PL/SQL code, set the package variable uc_ai_anthropic.g_apex_web_credential to the static ID of your web credential before calling any UC AI functions:

uc_ai_anthropic.g_apex_web_credential := 'ANTHROPIC';

Anthropic builds a range of models called Claude. The Haiku models are optimized for speed and cost. The Sonnet models balance performance and speed. The Opus and Fable models are the most capable, and also the most expensive. See this model reference for details on each model. Refer to Artifical Analysis for a comparison of intelligence, speed, and price.

The UC AI Anthropic package provides constants for these Claude models:

  • uc_ai_anthropic.c_model_claude_5_5_opus - Claude Opus 5.5, for long-running agentic coding and knowledge work
  • uc_ai_anthropic.c_model_claude_5_5_sonnet - Claude Sonnet 5.5, the best combination of speed and intelligence
  • uc_ai_anthropic.c_model_claude_5_1_fable - Claude Fable 5.1, for demanding reasoning and long-running agents
  • uc_ai_anthropic.c_model_claude_4_5_haiku - Claude Haiku 4.5, the fastest model

This list shows the newest model of each family. The package keeps the constants of older models for code that still references them.

Anthropic retired the Claude 3 models, the Claude 4.0 models, and Claude Opus 4.1. The package keeps their constants for code that still references them, but requests with these models fail. See the Anthropic deprecation list for the dates.

declare
l_result json_object_t;
begin
l_result := uc_ai.generate_text(
p_user_prompt => 'What is Oracle APEX?',
p_provider => uc_ai.c_provider_anthropic,
p_model => uc_ai_anthropic.c_model_claude_5_sonnet
);
dbms_output.put_line('AI Response: ' || l_result.get_string('final_message'));
end;
/
declare
l_result json_object_t;
begin
l_result := uc_ai.generate_text(
p_user_prompt => 'I have tomatoes, salad, potatoes, olives, and cheese. What can I cook with that?',
p_system_prompt => 'You are an assistant helping users to get recipes. Please just list 3 possible dish names without instructions.',
p_provider => uc_ai.c_provider_anthropic,
p_model => uc_ai_anthropic.c_model_claude_4_5_haiku
);
dbms_output.put_line('Recipe suggestions: ' || l_result.get_string('final_message'));
end;
/

Anthropic requires an upper limit of generated tokens to be sent with API requests. UC AI defaults this setting to 8192. If you want to generate longer answers or reasoning sequences you have to increase this value:

uc_ai_anthropic.g_max_tokens := 32768;

All Claude models support tools/function calling. You can define tools in your application and Claude will call them as needed.

See the tools guide for details on how to set up and use tools.

Claude models support structured output with JSON schemas. UC AI automatically converts your schema to the format required by Anthropic’s API. See Anthropic’s structured output documentation for model support and best practices.

declare
l_result json_object_t;
l_schema json_object_t;
l_structured_output json_object_t;
begin
l_schema := json_object_t(q'#{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Simple AI Response",
"properties": {
"response": {
"type": "string",
"description": "The generated response text"
},
"confidence": {
"type": "number",
"description": "Confidence score between 0 and 1"
}
},
"required": ["response", "confidence"]
}#');
l_result := uc_ai.generate_text(
p_user_prompt => 'What is the capital of France? Please respond with confidence.',
p_system_prompt => 'You are a helpful assistant that provides accurate information.',
p_provider => uc_ai.c_provider_anthropic,
p_model => uc_ai_anthropic.c_model_claude_4_5_haiku,
p_response_json_schema => l_schema
);
l_structured_output := json_object_t(l_result.get_clob('final_message'));
dbms_output.put_line('Response: ' || l_structured_output.get_string('response'));
dbms_output.put_line('Confidence: ' || l_structured_output.get_number('confidence'));
-- Response: The capital of France is Paris.
-- Confidence: 1
end;
/

See the structured output guide for more details.

Claude models have vision capabilities for Image and PDF Analysis.

Refer to the file analysis guide for examples on how to analyze images and PDFs.

Claude models support reasoning. When you enable it, Claude reasons internally before it gives its final answer. Refer to Anthropics Extended Thinking guide for model support and best practices.

Make sure to set the uc_ai.g_enable_reasoning variable to true. Additionally you can configure the reasoning budget to limit the number of tokens used for reasoning:

declare
l_result json_object_t;
begin
uc_ai.g_enable_reasoning := true;
uc_ai_anthropic.g_reasoning_budget_tokens := 2048; -- Optional: set reasoning token budget
l_result := uc_ai.generate_text(
p_user_prompt => 'Why have relational databases been so successful?',
p_provider => uc_ai.c_provider_anthropic,
p_model => uc_ai_anthropic.c_model_claude_4_5_sonnet
);
dbms_output.put_line('AI Response: ' || l_result.get_string('final_message'));
end;
/

The response messages array includes the reasoning as content with type reasoning. Use it to inspect Claude’s thought process.