fix(toolkits): send API key for apiKey security schemes in cookies by BlueX888 · Pull Request #4375 · camel-ai/camel · GitHub
Skip to content

fix(toolkits): send API key for apiKey security schemes in cookies - #4375

Open
BlueX888 wants to merge 1 commit into
camel-ai:masterfrom
BlueX888:fix/prep-openapi-cookie-apikey-dropped
Open

BlueX888 wants to merge 1 commit into
camel-ai:masterfrom
BlueX888:fix/prep-openapi-cookie-apikey-dropped

Conversation

@BlueX888

Copy link
Copy Markdown

Related Issue

Closes #4371

Description

Summary

OpenAPIToolkit never injected the API key into the outgoing request when an OpenAPI security scheme declares {type: apiKey, in: cookie}, so the request was sent with no credentials at all. This PR fixes the branch literal so the key is sent as a cookie, in line with the query and header cases.

Why (root cause)

The security-scheme branch in camel/toolkits/open_api_toolkit.py:307 tested the misspelled literal 'coolie', which can never match the spec value 'cookie':

if request_key_in == 'query':
    params[request_key_name] = api_key_value
elif request_key_in == 'header':
    headers[request_key_name] = api_key_value
elif request_key_in == 'coolie':          # <- typo: never matches 'cookie'
    cookies[request_key_name] = api_key_value

The neighboring parameter branch of the same function already handles param['in'] == 'cookie' correctly (camel/toolkits/open_api_toolkit.py:324), so only the security-scheme branch was inconsistent. Per the OpenAPI 3.x specification, a securityScheme with type: apiKey allows in: 'query' | 'header' | 'cookie', so in: cookie is a valid configuration that silently got no key.

Changes

  • camel/toolkits/open_api_toolkit.py: fix the branch literal 'coolie' -> 'cookie' so the API key is placed in cookies for in: cookie security schemes.
  • test/toolkits/test_open_api_function.py: add test_api_key_in_cookie_security_scheme, which builds a spec with an apiKey / in: cookie security scheme, mocks requests.request, and asserts the key is passed in cookies (and not in params/headers).

Testing

  • New test on unpatched master fails: python -m pytest test/toolkits/test_open_api_function.py::test_api_key_in_cookie_security_scheme -> AssertionError: assert {} == {'session': '...et-token-123'} (1 failed)
  • With the fix, whole module test file: python -m pytest test/toolkits/test_open_api_function.py -> 12 passed (11 pre-existing + 1 new)
  • ruff check / ruff format --check on both changed files (ruff 0.7.4, the pinned pre-commit range): All checks passed! / 2 files already formatted
  • codespell on both changed files: clean
  • mypy --namespace-packages on both changed files: no errors in the changed files
  • python licenses/update_license.py . licenses/license_template.txt: License updated in 0 files
  • Unrelated note: test/toolkits/test_generate_openai_tool_schema.py::test_synthesize_openai_tool_schema fails the same way on unpatched master in my environment (it needs OPENAI_API_KEY); not touched by this PR.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Checklist

  • I have read and agree to the AI-Generated Code Policy (required)
  • I have linked this PR to an issue (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and run uv lock (no dependency changes)
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed (no documentation change needed)
  • I have added examples if this is a new feature (not a new feature)

A security scheme of type `apiKey` with `in: cookie` was never matched
because the security branch tested the misspelled literal `'coolie'`,
so the API key was silently dropped from the outgoing request. Align
it with the parameter branch, which already handles `'cookie'`.
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OpenAPIToolkit: security scheme in: cookie never gets its API key injected because the branch tests the misspelled literal 'coolie'

1 participant