DocsMaple Proxy

SDK examples

Use Maple Proxy from the OpenAI Python and JavaScript libraries or plain cURL. Change the base URL and API key, and keep the rest of your code.

Maple Proxy speaks OpenAI’s API, so you use the official OpenAI libraries. Change two things:

  • Base URL: http://127.0.0.1:8080/v1 (or wherever your proxy runs).
  • API key: your Maple API key.

The examples read the key from the MAPLE_API_KEY environment variable and use gpt-oss-120b. Swap in any ID from models.

Chat completions

Install the library first: pip install openai for Python, npm install openai for JavaScript.

Python
import os
from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8080/v1",
    api_key=os.environ["MAPLE_API_KEY"],
)

stream = client.chat.completions.create(
    model="gpt-oss-120b",
    messages=[{"role": "user", "content": "Explain TEEs in simple terms"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
TypeScript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'http://127.0.0.1:8080/v1',
  apiKey: process.env.MAPLE_API_KEY,
});

const stream = await client.chat.completions.create({
  model: 'gpt-oss-120b',
  messages: [{ role: 'user', content: 'Explain TEEs in simple terms' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
Shell
curl -N http://127.0.0.1:8080/v1/chat/completions \
  -H "Authorization: Bearer $MAPLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-oss-120b",
    "messages": [{"role": "user", "content": "Explain TEEs in simple terms"}],
    "stream": true
  }'

-N turns off cURL’s output buffering, so streamed tokens print as they arrive.

Building a JavaScript app?

@mapleai/sdk verifies the enclave and encrypts requests inside your app, with no proxy to run.

Embeddings

Python
result = client.embeddings.create(
    model="nomic-embed-text",
    input="Generate an embedding for this text",
)
print(len(result.data[0].embedding))
TypeScript
const result = await client.embeddings.create({
  model: 'nomic-embed-text',
  input: 'Generate an embedding for this text',
});
console.log(result.data[0].embedding.length);
Shell
curl http://127.0.0.1:8080/v1/embeddings \
  -H "Authorization: Bearer $MAPLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nomic-embed-text",
    "input": "Generate an embedding for this text"
  }'

Models and health

Shell
# Health check (no key, doesn't contact Maple)
curl http://127.0.0.1:8080/health

# List models
curl http://127.0.0.1:8080/v1/models \
  -H "Authorization: Bearer $MAPLE_API_KEY"

Using the desktop app’s saved key

With the desktop app’s Local Proxy and CORS off, local tools can rely on the key Maple saved. The OpenAI libraries still require an api_key value, so pass any placeholder:

Python
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="unused")

A real key sent by the client always takes priority over the saved one.

Last updated