This topic describes how to access OceanBase Cloud AI services through APIs compatible with OpenAI, Anthropic, and Vertex AI. Choose an API that matches your application's existing protocol and request format so that you can reuse your integration code for model access and testing.
Prerequisites
You have activated the AI service.
You have created a valid API key. For more information, see Manage AI API keys.
Calling method
You can call the AI API by using HTTP requests. Depending on the compatibility protocol you choose, use the following base URL and request headers:
OpenAI-compatible
- Base URL:
https://ai-api-g.oceanbase.com/api/v1 - Authentication: Request header
Authorization: Bearer YOUR_API_KEY
curl -X POST https://ai-api-g.oceanbase.com/api/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-5.4", "messages": [{"role": "user", "content": "Hello"}]}'
from openai import OpenAI
client = OpenAI(
base_url="https://ai-api-g.oceanbase.com/api/v1",
api_key="YOUR_API_KEY",
)
Anthropic-compatible
- Base URL:
https://ai-api-g.oceanbase.com/api/anthropic - Authentication: Request headers
x-api-key: YOUR_API_KEYandanthropic-version: 2023-06-01
curl -sS -X POST "https://ai-api-g.oceanbase.com/api/anthropic/v1/messages" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'
import anthropic
client = anthropic.Anthropic(
base_url="https://ai-api-g.oceanbase.com/api/anthropic",
api_key="YOUR_API_KEY",
)
Vertex AI-compatible
- Base URL:
https://ai-api-g.oceanbase.com/api/v1 - Authentication: Request header
Authorization: Bearer YOUR_API_KEY
curl -X POST "https://ai-api-g.oceanbase.com/api/v1/publishers/{provider}/models/{model}:generateContent" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Hello"}]}]
}'
Response examples
- Successful call
{
"id": "req_xxx",
"object": "chat.completion",
"created": 1710000000,
"model": "gpt-5.4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello, OceanBase Cloud AI."
}
}
]
}
- Failed call
{
"error": {
"code": "unauthorized",
"message": "Invalid API key."
}
}
