Getting started

API quickstart

Use this quickstart if you want to call the API from your own code or product, or use third-party integrations such as coding assistants.

Before you start

  • Sign in to the Privatemode portal.
  • Create or select an organization. Rate limits, usage, and billing are managed at the organization level.
  • Create an API key in the portal.

For more details, see Portal overview, Organizations, and API keys.

1. Create an API key

In the portal, go to API keys and create a new API key.

Save the key securely when it's shown to you. You will need it to authenticate the Privatemode SDK or proxy.

2. Connect to Privatemode

Choose the setup for your application's language.

The Privatemode SDK handles remote attestation and end-to-end encryption directly in your application.

Install the SDK

Install the package and make your API key available to the application:

npm i privatemode-ai
export PRIVATEMODE_API_KEY="<your-api-key>"

Send a prompt

Create a client and send your first prompt:

import { PrivatemodeAI } from 'privatemode-ai';

const client = new PrivatemodeAI({
  apiKey: process.env.PRIVATEMODE_API_KEY,
});

const response = await client.chat.completions.create({
  model: 'kimi-latest',
  messages: [{ role: 'user', content: 'Hello Privatemode!' }],
});

console.log(response.choices[0].message.content);

Example response

It's nice to meet you. Is there something I can help you with or would you like to chat?

Before sending the first request, the SDK verifies the Privatemode deployment and establishes an encryption secret.

See the SDK getting started guide for streaming and more examples.

The Privatemode proxy exposes a local OpenAI-compatible and Anthropic-compatible endpoint. It handles remote attestation and end-to-end encryption for applications and tools that don't use the JavaScript and TypeScript SDK.

Install Docker

Follow the instructions to install Docker.

Tip

On Windows, the easiest way is to run the proxy inside the Windows Subsystem for Linux (WSL) with the networking mode set to mirrored. Open "WSL Settings" and go to "Networking" to set the networking mode.

Run the proxy

The Privatemode API comes with its own proxy. The Privatemode proxy takes care of client-side encryption and verifies the integrity and identity of the entire service using remote attestation. Use the following command to run the proxy:

docker run -p 8080:8080 ghcr.io/edgelesssys/privatemode/privatemode-proxy:latest --apiKey <your-api-key>

Tip

Instead of using Docker, you may run the native binary on Linux.

This opens an endpoint on your host on port 8080. This guide assumes that you run and use the proxy on your local machine. Alternatively, you can run it on another machine and configure TLS encryption.

Send a prompt

Now you're all set to use the API. The proxy handles all the security and confidential computing details for you. Start by sending your first prompt:

Example request

#!/usr/bin/env bash

curl localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-latest",
    "messages": [
      {
        "role": "user",
        "content": "Hello Privatemode!"
      }
    ]
  }'

Example response

{
  "id": "chatcmpl-proxy_021e5a68-0346-432b-a0f0-7b516ab0c9a7_0",
  "object": "chat.completion",
  "created": 1776086356,
  "model": "kimi-latest",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": " Hello! I'm Kimi, ...",
        "refusal": null,
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": [],
        "reasoning": " The user greeted me ... ",
        "reasoning_content": " The user greeted me ... "
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": 163586,
      "token_ids": null
    }
  ],
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "prompt_tokens": 30,
    "total_tokens": 420,
    "completion_tokens": 390,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null,
  "prompt_token_ids": null,
  "kv_transfer_params": null
}

Example request

import openai

client = openai.OpenAI(
    api_key="placeholder",  # Already set in the proxy, but needs to be non-empty here
    base_url="http://localhost:8080/v1",  # Adjust as necessary
)

response = client.chat.completions.create(
    model="kimi-latest",
    messages=[
        {"role": "user", "content": "Hello Privatemode!"},
    ],
)

print(response.choices[0].message.content)

Example response

It's nice to meet you. Is there something I can help you with or would you like to chat?

The code performs the following steps:

  1. Construct a prompt request following the OpenAI Chat API specification.
  2. Send the prompt request to the Privatemode proxy. The proxy handles end-to-end encryption and verifies the integrity of the Privatemode backend that serves the endpoint.
  3. Receive and print the response.

Info

Privatemode doesn't use any OpenAI services. It only adheres to the same interface definitions to provide a great development experience and ensure easy code portability.

Next steps