MuseSpark
MuseSpark
Start here

Gemini-compatible quickstart

Send native contents and parts with explicit MuseSpark authentication.

Enable llm_compat and llm:invoke. Set MUSESPARK_API_KEY and replace YOUR_AUTHORIZED_MODEL_ID with an authorized Gemini model identifier.

curl

curl --fail-with-body \
  'https://api.musespark.ai/proxy/gemini/v1beta/models/YOUR_AUTHORIZED_MODEL_ID:generateContent' \
  -H "Authorization: Bearer $MUSESPARK_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"contents":[{"role":"user","parts":[{"text":"Explain asynchronous APIs in one sentence."}]}]}'

Python

Install requests in your server application.

import os
from urllib.parse import quote
import requests

model = quote("YOUR_AUTHORIZED_MODEL_ID", safe="")
response = requests.post(
    "https://api.musespark.ai/proxy/gemini/v1beta/models/" + model + ":generateContent",
    headers={"Authorization": "Bearer " + os.environ["MUSESPARK_API_KEY"]},
    json={"contents": [{"role": "user", "parts": [
        {"text": "Explain asynchronous APIs in one sentence."}
    ]}]},
    timeout=120,
)
response.raise_for_status()
result = response.json()
for candidate in result.get("candidates", []):
    for part in candidate.get("content", {}).get("parts", []):
        if "text" in part:
            print(part["text"])

JavaScript

const model = encodeURIComponent('YOUR_AUTHORIZED_MODEL_ID');
const response = await fetch(`https://api.musespark.ai/proxy/gemini/v1beta/models/${model}:generateContent`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MUSESPARK_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ contents: [{ role: 'user', parts: [
    { text: 'Explain asynchronous APIs in one sentence.' },
  ] }] }),
  signal: AbortSignal.timeout(120_000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
for (const candidate of result.candidates ?? []) {
  for (const part of candidate.content?.parts ?? []) {
    if (part.text) console.log(part.text);
  }
}

SDK configuration

A Gemini SDK must allow both the MuseSpark base path and a supported authentication header. Check its actual outgoing URL and headers. The direct HTTP examples avoid assuming that a vendor SDK's default API-key transport authenticates this gateway.

Multimodal parts and generation options depend on model support. See Generate Content for the operation contract.

If the request fails

  • For HTTP 401, verify the API key and credential header.
  • For HTTP 403, check the llm_compat product, invocation scope, and access to the selected model.
  • If optional fields are rejected, check the model's supported capabilities and the operation reference.
  • If a call times out after submission, treat its execution as uncertain. The task API's idempotency mechanism does not apply to compatibility calls; replaying the request can start another paid execution.

Next steps