OpenAI

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://app.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.

“Hello World” (Python, Node.js)

Python

from openai import OpenAI

client = OpenAI(
    api_key="eyJhb...",  # Credal API key created at <https://app.credal.ai/api-tokens>
    base_url="<https://app.credal.ai/api/openai>",
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Hello world!",
        }
    ],
    model="gpt-4o",
)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "eyJh...", // Credal API key created at <https://app.credal.ai/api-tokens>
  baseURL: "<https://app.credal.ai/api/openai>",
});

const chatCompletion = await client.chat.completions.create({
  messages: [{ role: "user", content: "Hello world" }],
  model: "gpt-4o",
});

Embeddings

from openai import OpenAI

client = OpenAI(
    api_key="eyJhb...",  # Credal API key created at <https://app.credal.ai/api-tokens>
    base_url="<https://app.credal.ai/api/openai>",
)

client.embeddings.create(input="Hello world", model="text-embedding-3-small")

Whisper Audio Transcription

from openai import OpenAI

client = OpenAI(
    api_key="eyJhb...",  # Credal API key created at <https://app.credal.ai/api-tokens>
    base_url="<https://api.credal.ai/api/openai>",
)

with open("...x.mp3", "rb") as f:
    transcription = client.audio.transcriptions.create(
		  model="whisper-1", 
		  file=f,
		)

Credal Metadata

The API returns an additional credal field with blocks or warnings to surface to your users.

Warnings

client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "My email address is [email protected]",
        }
    ],
    model="gpt-4o",
)

ChatCompletion(
	id='chatcmpl-9xheezr0FRbbjtorrLjqpeXqdtBBC',
	...
	credal={'blocked': [], 'warnings': ["[email protected]"]}
)

Blocks