Credal offers drop-in support for the most common endpoints for text and chat completions, including all customization parameters that OpenAI offers. Take advantage of Credal with your existing OpenAI code, and feel free use the official OpenAI Python or Node.js libraries!
Base URL: https://api.credal.ai/api/openai
API Key: Create a Credal API key
Your Credal API key connects requests to your Credal account. By default your request will use Credal’s own capacity. If you’ve already configured Credal to use your own OpenAI or Azure keys, requests will then be routed through those accounts.
Python
import openai
openai.api_base = "<https://api.credal.ai/api/openai>"
openai.api_key = "example-credal-API-key" # <https://app.credal.ai/api-tokens>
openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world!"}]
)
Node.js
import { Configuration, OpenAIApi } from "openai";
const OPENAI_CLIENT = new OpenAIApi(
new Configuration({
apiKey: "example-credal-API-key", // <https://app.credal.ai/api-tokens>
basePath: "<https://api.credal.ai/api/openai>",
}),
);
const completion = await OPENAI_CLIENT.createChatCompletion({
model: "gpt-4",
messages: [{ role: "user", content: "Hello world!" }],
});
import openai
openai.api_base = "<https://api.credal.ai/api/openai>"
openai.api_key = "example-credal-API-key" # <https://app.credal.ai/api-tokens>
embedding = openai.Embedding.create(
input="Your text goes here", model="text-embedding-ada-002"
)
import openai
openai.api_base = "<https://api.credal.ai/api/openai>"
openai.api_key = "example-credal-API-key" # <https://app.credal.ai/api-tokens>
with open("...x.mp3", "rb") as f:
transcription = openai.Audio.transcribe("whisper-1", f)
The API returns an additional credal
field with blocks or warnings to surface to your users.
Warnings
openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "My email address is [email protected]"}],
)
<OpenAIObject chat.completion id=chatcmpl-7CEssbIvMZZT9woo3M2c8KK4TqNZP at 0x1184574d0> JSON: {
"id": "chatcmpl-7CEssbIvMZZT9woo3M2c8KK4TqNZP",
"model": "gpt-3.5-turbo-0301",
...
"credal": {
"blocked": [],
"warnings": [
"[email protected]"
]
}
}
Blocks