Skip to main content

Incredible API Python SDK compatible with Anthropics' client interface

Project description

Incredible Python SDK

Drop-in replacement for the Anthropic Python SDK that speaks to the Incredible API. The goal is plug-and-play migration: swap anthropic.Anthropic for incredible_python.Incredible and keep the rest of your code unchanged—function calling, streaming, token counting, and multi-step workflows included.


Table of Contents

  1. Features
  2. Installation
  3. Configuration
  4. Quick Start
  5. Function Calling
  6. Streaming Responses
  7. Token Counting
  8. Cookbook Compatibility
  9. Testing & Development
  10. Contributing
  11. License

Features

  • Anthropic-compatible client: identical constructor and method signatures where possible.
  • Function/tool calling: pass functions (and tools) to messages.create and receive structured tool-use events.
  • Streaming support: iterate over server-sent events that follow Anthropic semantics (data: ..., [DONE]).
  • Utility helpers: helper functions to create function_call / function_call_result messages when you run tools locally.
  • Token counting: call client.messages.count_tokens(...) to estimate usage before executing a request.
  • Cookbook-ready: all examples in Incredible-API-Cookbook-main/ can now be executed with this SDK.

Installation

From source (recommended during development)

# create and activate a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# install in editable mode
pip install -e .

(Future) From PyPI

When the package is published you will be able to run:

pip install incredible-python

Configuration

The client reads configuration from keyword arguments or environment variables—mirroring the Anthropic SDK.

Setting Env Var Default
API key INCREDIBLE_API_KEY (required)
Base URL INCREDIBLE_BASE_URL https://api.incredible.one
Timeout 600 seconds
Max retries 2 (with backoff)
export INCREDIBLE_API_KEY="your-secret-key"

Quick Start

from incredible_python import Incredible

client = Incredible()
response = client.messages.create(
    model="small-1",
    max_tokens=256,
    messages=[
        {"role": "user", "content": "Give me three startup ideas."}
    ],
)
print(response.content[0]["text"])

response is a rich object that exposes Anthropic-style properties:

print(response.tool_calls)     # list of ToolCall objects (if any)
print(response.usage)          # token usage metadata (if provided)
print(response.stop_reason)    # e.g. "end_turn", "stop_sequence"

Function Calling

Provide tool schemas via functions

Important: If you need to work with large context (e.g., multi-megabyte datasets or long documents), register a function/tool that returns that data instead of pasting it directly into a message. The Incredible API assumes heavy payloads are fetched on demand via tool calls; injecting them into the prompt will overflow the current context window.

(or tools) when calling messages.create. If the Incredible model decides to call your function, you can execute it locally and send a follow-up message using the helper utilities.

Manual control

from incredible_python import Incredible, helpers

client = Incredible()

functions = [
    {
        "name": "calculate_operation",
        "description": "Perform basic math",
        "parameters": {
            "type": "object",
            "properties": {
                "operation": {"type": "string", "enum": ["add", "subtract", "multiply", "divide"]},
                "a": {"type": "number"},
                "b": {"type": "number"},
            },
            "required": ["operation", "a", "b"],
        },
    }
]

initial = client.messages.create(
    model="small-1",
    max_tokens=64,
    messages=[{"role": "user", "content": "What is 24 multiplied by 7?"}],
    functions=functions,
)

for call in initial.tool_calls:
    result_value = call.arguments["a"] * call.arguments["b"]
    function_result = helpers.make_tool_result(call.id, result_value)

    follow_up_messages = [
        {"role": "user", "content": "What is 24 multiplied by 7?"},
        helpers.make_tool_call(call.name, call.arguments, call_id=call.id),
        function_result,
    ]

    final = client.messages.create(
        model="small-1",
        max_tokens=128,
        messages=follow_up_messages,
        functions=functions,
    )
    print(final.content)

Automated helper flow

When the model returns a function_call block you can offload the parsing and follow-up message creation to the helper utilities:

from incredible_python import Incredible, helpers

client = Incredible()
registry = {
    "calculate_operation": lambda operation, a, b: eval(f"{a}{ {'add':'+','subtract':'-','multiply':'*','divide':'/' }[operation] }{b}"),
}

messages = [{"role": "user", "content": "Calculate 42 / 7."}]
response = client.messages.create(
    model="small-1",
    max_tokens=64,
    messages=messages,
    functions=list_registry_as_json_schema(...),  # supply your schemas as before
)

plan = helpers.build_tool_execution_plan(response.raw)
if plan and not plan.is_empty():
    results = helpers.execute_plan(plan, registry=registry)
    follow_up = helpers.build_follow_up_messages(messages, plan, results)
    final = client.messages.create(
        model="small-1",
        max_tokens=64,
        messages=follow_up,
        functions=list_registry_as_json_schema(...),
    )
    print(final.content)

Tip: execute_plan takes care of running multiple tool calls in the order the model requested. build_follow_up_messages packages the results back into the canonical function_call_result format required by the API.


Streaming Responses

client = Incredible()
stream = client.messages.stream(
    model="small-1",
    max_tokens=256,
    messages=[{"role": "user", "content": "Stream a short poem about the ocean."}],
)

for event in stream.iter_lines():
    if event.get("content", {}).get("type") == "content_chunk":
        chunk = event["content"]["content"]
        print(chunk, end="", flush=True)

StreamBuilder.iter_lines() yields parsed JSON events; when the server sends data: [DONE] the iterator stops. Call stream.close() to release the network connection early if needed.


Token Counting

usage_estimate = client.messages.count_tokens(
    model="small-1",
    messages=[{"role": "user", "content": "Summarise this 1,000 word article."}],
)
print(usage_estimate)

Note: The live Incredible API has not yet exposed /v1/messages/count_tokens, so this method will raise a 404 until the endpoint ships. The SDK keeps the method for future compatibility and mirrors Anthropic’s signature.


Cookbook Compatibility

This SDK was validated against every scenario in Incredible-API-Cookbook-main:

  • 01-getting-started/ – basic chat, conversations, streaming, function calling
  • 02-function-calling/ – multiple tools, advanced multi-step workflows, JSON extraction, and more

To migrate an example:

  1. Replace raw requests.post(...) calls with client.messages.create(...) or client.messages.stream(...).
  2. Use the helper utilities to create intermediate function_call / function_call_result messages when you execute tools locally.
  3. Profit! No other structural changes are required.

Testing & Development

# install dev dependencies
pip install -r requirements.txt

# run unit tests (add more as the SDK grows)
pytest

# run lint/format tools if configured (e.g. ruff, black)

The repository ships with a .venv/ suggestion for isolation; feel free to use your own environment manager.


Contributing

Pull requests are welcome! Please:

  1. Fork & clone the repository.
  2. Create a topic branch (git checkout -b feat/awesome-improvement).
  3. Add tests for new functionality when possible.
  4. Open a PR describing the change and cookbook scenarios it improves.

For major changes, open an issue first to discuss what you’d like to see.


License

MIT License. See LICENSE.


Integrations

The SDK wraps the /v1/integrations endpoints so you can enumerate, connect, and execute third-party apps with just a few lines of code.

client = Incredible()

# List available integrations
for integration in client.integrations.list():
    print(integration["id"], integration["name"])

# Fetch details for a specific integration
perplexity = client.integrations.retrieve("perplexity")
print(perplexity["features"])

# Connect a user (API key example)
client.integrations.connect(
    "perplexity",
    user_id="user_123",
    api_key="perplexity-secret",
)

# Execute a feature from a connected integration
result = client.integrations.execute(
    "perplexity",
    user_id="user_123",
    feature_name="PERPLEXITY_SEARCH",
    inputs={"query": "Latest AI news"},
)
print(result)

Supports both API key and OAuth flows via the same connect call—pass api_key or callback_url depending on the integration’s auth_method.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

incredible_python-0.1.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

incredible_python-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file incredible_python-0.1.1.tar.gz.

File metadata

  • Download URL: incredible_python-0.1.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for incredible_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 002e3824b8e16e49c2b6860cfaf454e0912bbc0bdc61a19aee69b4806a11df9f
MD5 17c37c38f4eed5cb1bcb7827cd3e3b30
BLAKE2b-256 fd2b80d482c922d6a5fd7182c0985f376a0a95e3d63dce6ea04928c4ed499c0a

See more details on using hashes here.

File details

Details for the file incredible_python-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for incredible_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28b1c032dc2c5dad02beed8afc8a04c06c7be7a420d30b46668d04d84ab96055
MD5 67103699e3b2f5d72b9d0cc45f83e782
BLAKE2b-256 a780d61393e8abd14aa0b2c42e9730bac9acdb5eea47067341cc1d230ca6171b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page